在logback

时间:2016-05-03 06:43:00

标签: java logging spring-boot logback janino

我们有一个spring-boot项目并配置logback-spring.xml,如下所示

<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="true">
<include resource="org/springframework/boot/logging/logback/base.xml" />

<define name="INCLUDED_FILE_EXISTS"
    class=" ch.qos.logback.core.property.FileExistsPropertyDefiner">
    <path>application.properties</path>
</define>

<if condition='property("INCLUDED_FILE_EXISTS").equals("true")'>
    <then>
        <property resource="application.properties" />
    </then>
</if> 

<property resource = "config/application.properties" />

    ...
</configuration>

由于在不同模式(例如,开发或生产)中将存在不同的属性,我们希望以上述配置条件处理属性资源。如果application.properties文件存在则会加载,而config / application.properties将始终加载。

但是,启动时出现以下错误:

14:21:09,923 |-ERROR in ch.qos.logback.core.joran.action.DefinePropertyAction - Could not create an PropertyDefiner of type [ ch.qos.logback.core.property.FileExistsPropertyDefiner]. ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type  ch.qos.logback.core.property.FileExistsPropertyDefiner
at ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type  ch.qos.logback.core.property.FileExistsPropertyDefiner
at  at ch.qos.logback.core.util.OptionHelper.instantiateByClassNameAndParameter(OptionHelper.java:73)
at  at ch.qos.logback.core.util.OptionHelper.instantiateByClassName(OptionHelper.java:48)
at  at ch.qos.logback.core.util.OptionHelper.instantiateByClassName(OptionHelper.java:35)
at  at ch.qos.logback.core.joran.actcion.DefinePropertyAction.begin(DefinePropertyAction.java:73)
at  at ch.qos.logback.core.joran.spi.Interpreter.callBeginAction(Interpreter.java:275)
at  at ch.qos.logback.core.joran.spi.Interpreter.startElement(Interpreter.java:147)
at  at ch.qos.logback.core.joran.spi.Interpreter.startElement(Interpreter.java:129)
at  at ch.qos.logback.core.joran.spi.EventPlayer.play(EventPlayer.java:50)
at  at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:149)
at  at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:135)
at  at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:99)
at  at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:49)
at  at org.springframework.boot.logging.logback.LogbackLoggingSystem.configureByResourceUrl(LogbackLoggingSystem.java:165)
at  at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:137)
at  at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithConventions(AbstractLoggingSystem.java:71)
at  at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:49)
at  at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:106)
at  at org.springframework.boot.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:262)
at  at org.springframework.boot.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:233)
at  at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:200)
at  at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:176)
at  at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:163)
at  at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:136)
at  at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:119)
at  at org.springframework.boot.context.event.EventPublishingRunListener.publishEvent(EventPublishingRunListener.java:111)
at  at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:65)
at  at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
at  at org.springframework.boot.SpringApplication.doRun(SpringApplication.java:325)
at  at org.springframework.boot.SpringApplication.run(SpringApplication.java:305)
at  at org.springframework.boot.context.web.SpringBootServletInitializer.run(SpringBootServletInitializer.java:149)
at  at org.springframework.boot.context.web.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:129)
at  at org.springframework.boot.context.web.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:85)
at  at com.ute.dc.tenant.ServletInitializer.onStartup(ServletInitializer.java:29)
at  at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:175)
at  at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5156)
at  at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at  at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409)
at  at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1399)
at  at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at  at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException:  ch.qos.logback.core.property.FileExistsPropertyDefiner
    at  at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1305)
    at  at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1157)
    at  at ch.qos.logback.core.util.OptionHelper.instantiateByClassNameAndParameter(OptionHelper.java:60)
    at  ... 41 common frames omitted
14:21:09,925 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@6:67 - ActionException in Action for tag [define] ch.qos.logback.core.joran.spi.ActionException: ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type  ch.qos.logback.core.property.FileExistsPropertyDefiner
    at ch.qos.logback.core.joran.spi.ActionException: ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type  ch.qos.logback.core.property.FileExistsPropertyDefiner
    at  at ch.qos.logback.core.joran.action.DefinePropertyAction.begin(DefinePropertyAction.java:84)
    at  at ch.qos.logback.core.joran.spi.Interpreter.callBeginAction(Interpreter.java:275)
    at  at ch.qos.logback.core.joran.spi.Interpreter.startElement(Interpreter.java:147)
    at  at ch.qos.logback.core.joran.spi.Interpreter.startElement(Interpreter.java:129)
    at  at ch.qos.logback.core.joran.spi.EventPlayer.play(EventPlayer.java:50)
    at  at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:149)
    at  at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:135)
    at  at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:99)
    at  at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:49)
    at  at org.springframework.boot.logging.logback.LogbackLoggingSystem.configureByResourceUrl(LogbackLoggingSystem.java:165)
    at  at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:137)
    at  at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithConventions(AbstractLoggingSystem.java:71)
    at  at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:49)
    at  at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:106)
    at  at org.springframework.boot.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:262)
    at  at org.springframework.boot.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:233)
    at  at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:200)
    at  at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:176)
    at  at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:163)
    at  at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:136)
    at  at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:119)
    at  at org.springframework.boot.context.event.EventPublishingRunListener.publishEvent(EventPublishingRunListener.java:111)
    at  at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:65)
    at  at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
    at  at org.springframework.boot.SpringApplication.doRun(SpringApplication.java:325)
    at  at org.springframework.boot.SpringApplication.run(SpringApplication.java:305)
    at  at org.springframework.boot.context.web.SpringBootServletInitializer.run(SpringBootServletInitializer.java:149)
    at  at org.springframework.boot.context.web.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:129)
    at  at org.springframework.boot.context.web.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:85)
    at  at com.ute.dc.tenant.ServletInitializer.onStartup(ServletInitializer.java:29)
    at  at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:175)
    at  at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5156)
    at  at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at  at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409)
    at  at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1399)
    at  at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at  at java.lang.Thread.run(Thread.java:745)
Caused by: ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type  ch.qos.logback.core.property.FileExistsPropertyDefiner
    at  at ch.qos.logback.core.util.OptionHelper.instantiateByClassNameAndParameter(OptionHelper.java:73)
    at  at ch.qos.logback.core.util.OptionHelper.instantiateByClassName(OptionHelper.java:48)
    at  at ch.qos.logback.core.util.OptionHelper.instantiateByClassName(OptionHelper.java:35)
    at  at ch.qos.logback.core.joran.action.DefinePropertyAction.begin(DefinePropertyAction.java:73)
    at  ... 38 common frames omitted
Caused by: java.lang.ClassNotFoundException:  ch.qos.logback.core.property.FileExistsPropertyDefiner
    at  at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1305)
    at  at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1157)
    at  at ch.qos.logback.core.util.OptionHelper.instantiateByClassNameAndParameter(OptionHelper.java:60)
    at  ... 41 common frames omitted

我们使用的logback是来自spring-boot-starter-logging 1.3.1-RELEASE的1.1.3,我们使用的条件处理的janino lib是2.7.8。我们没有声明janino的版本,但它是v2.7.8,我不知道为什么。

    <dependency>
        <groupId>org.codehaus.janino</groupId>
        <artifactId>janino</artifactId>
    </dependency>

我们有什么遗漏吗?任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:3)

双引号Search (_=_ -> _+_=_+_). 与包名称之间的空格字符错位:

"

应该是:

class=" ch.qos.logback.core.property.FileExistsPropertyDefiner"