【问题标题】:spring-boot-starter-cache with camunda shows java.lang.NoClassDefFoundError: org/apache/log4j/Priority class not foundspring-boot-starter-cache with camunda 显示 java.lang.NoClassDefFoundError: org/apache/log4j/Priority class not found
【发布时间】:2018-01-25 02:46:53
【问题描述】:

我正在使用 camunda(一个业务流程工具,不确定是否与它有关)。 pom.xml 在下面(仅删除了标头和 maven 构建插件)。

当我在 Tomcat 中构建和部署时,我得到“java.lang.NoClassDefFoundError: org/apache/log4j/Priorityorg/apache/log4j/Priority”。堆栈跟踪如下。

<properties>
    <java.version>1.8</java.version>
    <camunda-bom.version>7.6.0</camunda-bom.version>
    <mssql-jdbc.version>6.2.0.jre8</mssql-jdbc.version>
    <resteasy-spring-boot-starter.version>2.3.2-RELEASE</resteasy-spring-boot-starter.version>
</properties>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.4.RELEASE</version>
</parent>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.camunda.bpm</groupId>
            <artifactId>camunda-bom</artifactId>
            <version>${camunda-bom.version}</version>
            <scope>import</scope>
            <type>pom</type>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <!-- Camunda Engine -->
    <dependency>
        <groupId>org.camunda.bpm</groupId>
        <artifactId>camunda-engine</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.camunda.bpm</groupId>
        <artifactId>camunda-engine-spring</artifactId>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.camunda.bpm</groupId>
        <artifactId>camunda-engine-rest</artifactId>
        <classifier>classes</classifier>
    </dependency>

    <!-- Spring Boot Starters -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>       
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-cache</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
    </dependency>

    <!-- MS-SqlServer -->
    <dependency>
        <groupId>com.microsoft.sqlserver</groupId>
        <artifactId>mssql-jdbc</artifactId>
        <version>${mssql-jdbc.version}</version>
    </dependency>

    <!-- RestEasy -->
    <dependency>
        <groupId>com.paypal.springboot</groupId>
        <artifactId>resteasy-spring-boot-starter</artifactId>
        <version>${resteasy-spring-boot-starter.version}</version>
    </dependency>

    <!-- Ehcache -->
    <dependency>
        <groupId>net.sf.ehcache</groupId>
        <artifactId>ehcache</artifactId>
        <!-- <version>2.10.4</version> -->
    </dependency>
</dependencies>

堆栈跟踪如下:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'freeMarkerConfigurer' defined in class path resource [org/springframework/boot/autoconfigure/freemarker/FreeMarkerAutoConfiguration$FreeMarkerWebConfiguration.class]: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org/apache/log4j/Priority
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:564)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
        at org.springframework.boot.web.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:151)
        at org.springframework.boot.web.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:131)
        at org.springframework.boot.web.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:86)
        at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:169)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5156)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        ... 10 more
Caused by: java.lang.NoClassDefFoundError: org/apache/log4j/Priority
        at freemarker.log._Log4JLoggerFactory.getLogger(_Log4JLoggerFactory.java:67)
        at freemarker.log.Logger.getLogger(Logger.java:284)
        at freemarker.ext.jsp.TaglibFactory.<clinit>(TaglibFactory.java:101)
        at org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer.setServletContext(FreeMarkerConfigurer.java:102)
        at org.springframework.web.context.support.ServletContextAwareProcessor.postProcessBeforeInitialization(ServletContextAwareProcessor.java:103)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:409)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1620)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
        ... 28 more
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Priority
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 36 more

我正在继续努力……任何线索都会有所帮助!

【问题讨论】:

    标签: log4j camunda spring-boot-starter


    【解决方案1】:

    我认为您缺少 log4j 依赖项。尝试将此添加到您的 pom 中

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-logging</artifactId>
    </dependency>
    

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-log4j2</artifactId>
    </dependency>
    

    Maven Repository

    Spring-Boot Logging

    【讨论】:

    • 不,已经试过了,其他的,比如 slf4f-over-log4 等......没有用。请看我下面的答案 - 它有效。但我还不确定问题的根本原因是什么。
    • 不,spring-boot-starter-logging 已经在我的 spring-boot-starter-data-jpa 中了。尝试了 spring-boot-starter-log4j2,并得到以下异常:Caused by: java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation (class org.apache.logging.slf4j.Log4jLoggerFactory loaded from file:/C:/Work/tomcat-camunda760/server/apache-tomcat-8.0.24/webapps/Clinical/WEB-INF/lib/log4j-slf4j-impl-2.7.jar). 我的以下答案有效。但我还不确定问题的根本原因是什么。
    【解决方案2】:

    我找到了一种解决方法,并且 Tomcat 干净利落地启动,没有出现上述错误。我的搜索表明在“FreeMarkerAutoConfigurer”bean 创建期间 spring-boot-starter-cache 中存在潜在的 classLoader 问题。我不是 100% 确定原因,但以下修复对我有用。

    为了覆盖上面的“FreeMarkerAutoConfigurer”bean创建问题,我在pom下面添加了依赖:

    <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-freemarker</artifactId> </dependency>

    Tomcat 现在可以正常启动,并且我已经验证了使用 Spring 注释进行缓存有效。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-14
      • 1970-01-01
      相关资源
      最近更新 更多