gpt4 book ai didi

java.lang.NoClassDefFoundError : Could not initialize class org. apache.commons.logging.LogFactory

转载 作者:行者123 更新时间:2023-12-01 12:49:01 25 4
gpt4 key购买 nike

我是 Google App Engine 的新手。我收到此错误:

java.lang.NoClassDefFoundError: Could not initialize class 
org.apache.commons.logging.LogFactory at
org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:282) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106) at
org.mortbay.jetty.handler.ContextHandler.startContext(ContextHandler.java:548) at
org.mortbay.jetty.servlet.Context.startContext(Context.java:136) at ...

我已经添加了 slf4j 依赖项并在 spring-context 依赖项中排除了 commons-logging,但仍然收到此错误。该应用程序在我的本地计算机上运行得很好,但在部署到 App Engine 时出现此错误。

最佳答案

感谢this blog ,我能够解决这个问题:

Commons-logging is a dependency of many frameworks, Spring included. On the local server, everything runs fine. In the cloud, Google App Engine infrastructure replaces the commons-logging-1.1.1.jar with a JAR of its own that has a different package structure. In effect, that means you get funny NoClassDefFoundError on org.apache.commons.logging.LogFactory even though you included the JAR as a dependency. The solution is to still include the classes, but to give the JAR another name.

Since I use Maven, I removed the commons-logging dependency from the WAR with the exclusion tag for Spring and MyFaces artifact. Then, I added a dependency on commons-logging:commons-logging-api:1.1:jar with the runtime scope. This jar won’t be replaced.

所以你应该从 Spring 中排除 commons-logging :

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework.version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>

然后添加对具有运行时范围的 commons-logging-1.1 的依赖项:

<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging-api</artifactId>
<version>1.1</version>
<scope>runtime</scope>
</dependency>

关于java.lang.NoClassDefFoundError : Could not initialize class org. apache.commons.logging.LogFactory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24401006/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com