javaloggingspring-bootlogbackjanino

FileExistsPropertyDefiner class not found when using conditional processing in logback


We have a spring-boot project and configure the logback-spring.xml as below

<?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>

Since there will have different properties in different modes (e.g., dev or production), we want to conditional processing the property resource as above configuration. If the application.properties file is existed then it will be loaded in, whereas config/application.properties will always be loaded-in.

However, we got the following error when boot-up:

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

The logback we used is 1.1.3 from spring-boot-starter-logging 1.3.1-RELEASE and the janino lib for conditional processing we used is 2.7.8. We didn't declare the version of janino, but it goes to v2.7.8 which I didn't know why.

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

Are there has anything we miss? Any help is appreciated.


Solution

  • You have a misplaced space character between the double quote " and the package name:

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

    Should be:

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