1

我正在使用 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

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

4

2 回答 2

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 存储库

Spring-Boot 日志记录

于 2017-08-16T20:29:58.237 回答
0

我找到了一种解决方法,并且 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 注释的缓存可以正常工作。

于 2017-08-16T20:58:12.053 回答