gpt4 book ai didi

将 jar 标记为提供时出现 java.lang.NoClassDefFoundError

转载 作者:行者123 更新时间:2023-11-28 23:33:48 26 4
gpt4 key购买 nike

我的 webapp 有以下依赖:

<!-- swagger -->
<dependency>
<groupId>com.mangofactory</groupId>
<artifactId>swagger-springmvc</artifactId>
<version>${version.swagger.springmvc}</version>
</dependency>

我想减小 war 文件的大小,所以我将 swagger jar 标记为已提供:

<!-- swagger -->
<dependency>
<groupId>com.mangofactory</groupId>
<artifactId>swagger-springmvc</artifactId>
<version>${version.swagger.springmvc}</version>
<scope>provided</scope>
</dependency>

我将 swagger jar 添加到 tomcat 的公共(public) lib 文件夹中,因此它应该在运行时由 tomcat 提供,但是当我尝试部署该应用程序时,我遇到了这个异常:

java.lang.IllegalStateException: Cannot load configuration class: com.mangofactory.swagger.configuration.DocumentationConfig
at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:368)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:244)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:633)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:461)
at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:651)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:599)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:665)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:518)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:459)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
at javax.servlet.GenericServlet.init(GenericServlet.java:158)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1279)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1192)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1087)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5210)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5493)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:744)
Caused by: java.lang.NoClassDefFoundError: com/fasterxml/classmate/TypeResolver
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2688)
at java.lang.Class.getDeclaredMethods(Class.java:1962)
at org.springframework.cglib.core.ReflectUtils.addAllMethods(ReflectUtils.java:348)
at org.springframework.cglib.proxy.Enhancer.getMethods(Enhancer.java:421)
at org.springframework.cglib.proxy.Enhancer.generateClass(Enhancer.java:456)
at org.springframework.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216)
at org.springframework.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)
at org.springframework.cglib.proxy.Enhancer.createClass(Enhancer.java:317)
at org.springframework.context.annotation.ConfigurationClassEnhancer.createClass(ConfigurationClassEnhancer.java:118)
at org.springframework.context.annotation.ConfigurationClassEnhancer.enhance(ConfigurationClassEnhancer.java:92)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:358)
... 23 more
Caused by: java.lang.ClassNotFoundException: com.fasterxml.classmate.TypeResolver
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1718)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1569)
... 36 more

我注意到问题来自 org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses 但我在没有提供范围的情况下在我的 pom 中声明了所有需要的 spring jar在没有提供的范围的情况下运行 webapp 它工作正常吗?

最佳答案

我认为问题来自另一个丢失的 jar。在堆栈跟踪中我们看到

Caused by: java.lang.ClassNotFoundException: com.fasterxml.classmate.TypeResolver

com.fasterxml.classmate.TypeResolver 存在于 jar classmate.jar 中,它是 swagger-springmvc 的依赖项。

当您使用范围编译时,swagger-springmvc 的依赖项也会被部署。提供范围后,您必须提供 swagger-springmvc jar 及其所有依赖项。这里需要提供classmate.jar。

关于将 jar 标记为提供时出现 java.lang.NoClassDefFoundError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27101338/

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