在应用程序属性spring文件中指定相对路径

时间:2018-06-14 12:33:23

标签: java spring spring-boot logback

我对同一个问题没有发现任何问题,但如果问题重复,我很抱歉。

我有这个application.properties文件:

## Logback
#logging.level.root=error
#logging.level.com.myapp.test=error
#logging.console=true
#logging.path=%AppData%/MyFolder/log
#logging.file=${logging.path}/logfile.log

这是我的logback.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>

    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{yyyy-MM-dd HH:mm:ss} [%t] [%F:%L] - %msg%n</pattern>
        </encoder>
    </appender>

    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>${logging.file}</file>
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <pattern>%d{yyyy-MM-dd HH:mm:ss} [%t] [%F:%L] - %msg%n</pattern>
        </encoder>
    </appender>

    <logger name="com.myapp.test" level="ERROR" additivity="false">
        <appender-ref ref="STDOUT" />
        <appender-ref ref="FILE" />
    </logger>

    <root level="ERROR">
        <appender-ref ref="STDOUT" />
    </root>

</configuration>

问题是我不知道如何在application.properties文件中指定相对路径%AppData%。我想使用%AppData%或类似,因为应用程序将在不同的服务器上运行,我想使用路径: C:\Users\$USERNAME\AppData\Roaming\MyFolder\log

这可能吗?

1 个答案:

答案 0 :(得分:1)

环境变量会自动映射到Spring配置中。所以你应该像任何其他配置变量一样使用它们:

HTTP Error 404.3 - Not Found
The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map.

Most likely causes:
It is possible that a handler mapping is missing. By default, the static file handler processes all content.
The feature you are trying to use may not be installed.
The appropriate MIME map is not enabled for the Web site or application. (Warning: Do not create a MIME map for content that users should not download, such as .ASPX pages or .config files.)
If ASP.NET is not installed.

Things you can try:
In system.webServer/handlers:
Ensure that the expected handler for the current page is mapped.
Pay extra attention to preconditions (for example, runtimeVersion, pipelineMode, bitness) and compare them to the settings for your application pool.
Pay extra attention to typographical errors in the expected handler line.
Please verify that the feature you are trying to use is installed.
Verify that the MIME map is enabled or add the MIME map for the Web site using the command-line tool appcmd.exe.
To set a MIME type, use the following syntax: %SystemRoot%\windows\system32\inetsrv\appcmd set config /section:staticContent /+[fileExtension='string',mimeType='string']
The variable fileExtension string is the file name extension and the variable mimeType string is the file type description.
For example, to add a MIME map for a file which has the extension ".xyz": appcmd set config /section:staticContent /+[fileExtension='.xyz',mimeType='text/plain']
Warning: Ensure that this MIME mapping is needed for your Web server before adding it to the list. Configuration files such as .CONFIG or dynamic scripting pages such as .ASP or .ASPX, should not be downloaded directly and should always be processed through a handler. Other files such as database files or those used to store configuration, like .XML or .MDF, are sometimes used to store configuration information. Determine if clients can download these file types before enabling them.
Install ASP.NET.
Create a tracing rule to track failed requests for this HTTP status code. For more information about creating a tracing rule for failed requests, click here.

Detailed Error Information:
Module     StaticFileModule
Notification       ExecuteRequestHandler
Handler    StaticFile
Error Code     0x80070032
Requested URL      http://localhost:7778/Service1.svc
Physical Path      C:\inetpub\WCFBolig\WCFBolig\Service1.svc
Logon Method       Anonymous
Logon User     Anonymous

请参阅Spring Boot - 24. Externalized Configuration