【发布时间】:2015-06-27 20:07:19
【问题描述】:
我正在使用 Spring、Logback 和 maven。我想将我的所有设置都放在我用 maven 构建的 jar 之外的属性中。 所以我从 Logback.xml 中移动了所有设置。现在看起来像:
<configuration>
<property resource="application.properties" />
<timestamp key="byDate" datePattern="yyyyMMdd"/>
<!-- Send messages to System.out - CONSOLE -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{5} - %msg%n</pattern>
</encoder>
<withJansi>true</withJansi>
</appender>
<!-- Send messages to a file -->
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>${logging.path}/${spring.application.name}-${byDate}.log</file>
<append>true</append>
<!-- encoders are assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{5} - %msg%n</pattern>
</encoder>
</appender>
<root level="${logging.level}">
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />
</root>
</configuration>
我的 application.properties 文件是:
#Spring settings
spring.application.name=MyApp
server.port=8087
# Logging settings
logging.level=INFO
logging.path=/Users/...some path.../logs/
我把这个放到豆子上:
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="file:application.properties"/>
</bean>
并从使用插件的 maven 构建中排除 application.properties:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<copy todir="target" overwrite="true">
<fileset dir="src/main/resources/">
<include name="*.properties"/>
</fileset>
</copy>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
但这对我不起作用。日志文件名松散的 datePattern 并且我在属性文件中所做的任何更改都没有改变。怎么了?请。
更新:没有错误。一切正常。我可以通过在 IDE 中运行来更改所有设置。所以我相信我在 maven build 上做错了什么。
【问题讨论】:
-
就我而言,没有错误。一切正常。我可以通过在 IDE 中运行来更改所有设置。所以我相信我在 maven build 上做错了什么。
-
"一切正常。" 那么你的问题是什么?
-
"一切正常。" - 在 IDE 中,仅在 IDE 中。使用 Maven 构建 jar 后我遇到了问题。