Search code examples
javaspringspring-bootlog4jnoclassdeffounderror

Error creating bean with name 'log4jConfigurer' defined in class path resource [common-context.xml]


I am using spring 4.x dependency jars in my spring boot 2.0.3 application and one of the classes in the jars depends on org.springframework.util.Log4jConfigurer

Below is the exception trace I get when starting the application

ERROR: org.springframework.boot.SpringApplication - Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'log4jConfigurer' defined in class path resource [common-context.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/util/Log4jConfigurer
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1708)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:581)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:503)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317)

Caused by: java.lang.NoClassDefFoundError: org/springframework/util/Log4jConfigurer
    at com.xyz.common.util.config.XyzLog4jConfigurer.initializeLog4JConfigurer(XyzLog4jConfigurer.java:58)
    at com.xyz.common.util.config.XyzLog4jConfigurer.init(XyzLog4jConfigurer.java:24)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1833)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1776)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1704)
    ... 24 more

I have the following ivy configuration corresponding to the class in the dependent project's ivy.xml

<dependency org="org.springframework" name="spring-core" rev="4.1.6" conf="compile->compile(*),master(*);runtime->runtime(*);all->default(*)"/>

I don't understand why does the error occur. Can someone help me fix this ?


Solution

  • It was because of spring boot version 2.0.3. I think Log4jConfigurer is deprecated in version 2.0. It was fixed by using spring boot 1.5.10.RELEASE