英文:
java.lang.NoClassDefFoundError when deploying Spring Boot .war within .ear on Wildfly with other deployments
问题
我在Wildfly上部署Spring Boot应用程序时遇到了java.lang.NoClassDefFoundError
错误,该应用程序以.war
文件形式打包在一个.ear
部署包中。只有在.ear
文件中包含其他部署时才会出现此错误。
然而,如果我将.war
文件部署在一个没有其他部署的新的Wildfly实例上,就不会遇到任何问题。
详细信息:
这是我看到的具体错误消息:
ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 142) MSC000001: Failed to start service jboss.deployment.subunit."interfaces2.ear"."redacted-kafka-consumer.war".undertow-deployment:
org.jboss.msc.service.StartException in service jboss.deployment.subunit."interfaces2.ear"."redacted-kafka-consumer.war".undertow-deployment: java.lang.RuntimeException: java.lang.IllegalStateException: Error processing con
dition on org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration.basicErrorController
...
这个错误似乎与Spring Framework的spring-boot-web
模块中的DefaultErrorAttributes
类有关。看起来类加载器无法找到必要的HandlerExceptionResolver
类,导致运行时的NoClassDefFoundError
错误。
附加信息:
- Spring Boot 版本: 2.7.11
- Wildfly 版本: 23
- Java 版本: 11
这是redacted-kafka-consumer
模块的pom.xml
文件中相关的依赖项:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>${servlet-api.version}</version>
<scope>provided</scope>
</dependency>
非常感谢您提供帮助或解决此问题的建议。谢谢!
英文:
I'm encountering a java.lang.NoClassDefFoundError
when deploying a Spring Boot application as a .war
file within a .ear
deployment on Wildfly. The error only occurs when there are other deployments included in the .ear
file.
However, if I deploy the .war
file on a fresh Wildfly instance with no other deployments, I don't encounter any issues.
Details:
Here's the specific error message I'm seeing:
ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 142) MSC000001: Failed to start service jboss.deployment.subunit."interfaces2.ear"."redacted-kafka-consumer.war".undertow-deployment:
org.jboss.msc.service.StartException in service jboss.deployment.subunit."interfaces2.ear"."redacted-kafka-consumer.war".undertow-deployment: java.lang.RuntimeException: java.lang.IllegalStateException: Error processing con
dition on org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration.basicErrorController
at org.wildfly.extension.undertow@23.0.2.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:81)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at org.jboss.threads@2.4.0.Final//org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
at org.jboss.threads@2.4.0.Final//org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1990)
at org.jboss.threads@2.4.0.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
at org.jboss.threads@2.4.0.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1348)
at java.base/java.lang.Thread.run(Thread.java:834)
at org.jboss.threads@2.4.0.Final//org.jboss.threads.JBossThread.run(JBossThread.java:513)
Caused by: java.lang.RuntimeException: java.lang.IllegalStateException: Error processing condition on org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration.basicErrorController
at io.undertow.servlet@2.2.5.Final//io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:257)
at org.wildfly.extension.undertow@23.0.2.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:96)
at org.wildfly.extension.undertow@23.0.2.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:78)
... 8 more
Caused by: java.lang.IllegalStateException: Error processing condition on org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration.basicErrorController
at deployment.interfaces2.ear.redacted-kafka-consumer.war//org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:60)
at deployment.interfaces2.ear//org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:108)
at deployment.interfaces2.ear//org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForBeanMethod(ConfigurationClassBeanDefinitionReader.java:193)
at deployment.interfaces2.ear//org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:153)
at deployment.interfaces2.ear//org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:129)
at deployment.interfaces2.ear//org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:343)
at deployment.interfaces2.ear//org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:247)
at deployment.interfaces2.ear//org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:311)
at deployment.interfaces2.ear//org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:112)
at deployment.interfaces2.ear//org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:748)
at deployment.interfaces2.ear//org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:564)
at deployment.interfaces2.ear//org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147)
at deployment.interfaces2.ear//org.springframework.boot.SpringApplication.refresh(SpringApplication.java:731)
at deployment.interfaces2.ear//org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408)
at deployment.interfaces2.ear//org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
at deployment.interfaces2.ear//org.springframework.boot.web.servlet.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:175)
at deployment.interfaces2.ear//org.springframework.boot.web.servlet.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:155)
at deployment.interfaces2.ear//org.springframework.boot.web.servlet.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:97)
at deployment.interfaces2.ear//org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:174)
at io.undertow.servlet@2.2.5.Final//io.undertow.servlet.core.DeploymentManagerImpl$1.call(DeploymentManagerImpl.java:204)
at io.undertow.servlet@2.2.5.Final//io.undertow.servlet.core.DeploymentManagerImpl$1.call(DeploymentManagerImpl.java:187)
at io.undertow.servlet@2.2.5.Final//io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
at org.wildfly.extension.undertow@23.0.2.Final//org.wildfly.extension.undertow.security.SecurityContextThreadSetupAction.lambda$create$0(SecurityContextThreadSetupAction.java:105)
at org.wildfly.extension.undertow@23.0.2.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1530)
at org.wildfly.extension.undertow@23.0.2.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1530)
at org.wildfly.extension.undertow@23.0.2.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1530)
at org.wildfly.extension.undertow@23.0.2.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1530)
at io.undertow.servlet@2.2.5.Final//io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:255)
... 10 more
Caused by: java.lang.IllegalStateException: Failed to introspect Class [org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration] from ClassLoader [ModuleClassLoader for Module "deployment.interfaces2.ear.redacted-kafka-consumer.war" from Service Module Loader]
at deployment.interfaces2.ear//org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:485)
at deployment.interfaces2.ear//org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:361)
at deployment.interfaces2.ear//org.springframework.util.ReflectionUtils.getUniqueDeclaredMethods(ReflectionUtils.java:418)
at deployment.interfaces2.ear//org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.lambda$getTypeForFactoryMethod$2(AbstractAutowireCapableBeanFactory.java:765)
at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1705)
at deployment.interfaces2.ear//org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryMethod(AbstractAutowireCapableBeanFactory.java:764)
at deployment.interfaces2.ear//org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:703)
at deployment.interfaces2.ear//org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:674)
at deployment.interfaces2.ear//org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1684)
at deployment.interfaces2.ear//org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:570)
at deployment.interfaces2.ear//org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:542)
at deployment.interfaces2.ear.redacted-kafka-consumer.war//org.springframework.boot.autoconfigure.condition.OnBeanCondition.collectBeanNamesForType(OnBeanCondition.java:246)
at deployment.interfaces2.ear.redacted-kafka-consumer.war//org.springframework.boot.autoconfigure.condition.OnBeanCondition.getBeanNamesForType(OnBeanCondition.java:239)
at deployment.interfaces2.ear.redacted-kafka-consumer.war//org.springframework.boot.autoconfigure.condition.OnBeanCondition.getBeanNamesForType(OnBeanCondition.java:229)
at deployment.interfaces2.ear.redacted-kafka-consumer.war//org.springframework.boot.autoconfigure.condition.OnBeanCondition.getMatchingBeans(OnBeanCondition.java:182)
at deployment.interfaces2.ear.redacted-kafka-consumer.war//org.springframework.boot.autoconfigure.condition.OnBeanCondition.getMatchOutcome(OnBeanCondition.java:157)
at deployment.interfaces2.ear.redacted-kafka-consumer.war//org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:47)
... 38 more
Caused by: java.lang.NoClassDefFoundError: Failed to link org/springframework/boot/web/servlet/error/DefaultErrorAttributes (Module "deployment.interfaces2.ear" from Service Module Loader): org/springframework/web/servlet/HandlerExceptionResolver
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1095)
at org.jboss.modules.ModuleClassLoader.doDefineOrLoadClass(ModuleClassLoader.java:424)
at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:555)
at org.jboss.modules.ModuleClassLoader.loadClassLocal(ModuleClassLoader.java:339)
at org.jboss.modules.ModuleClassLoader$1.loadClassLocal(ModuleClassLoader.java:126)
at org.jboss.modules.Module.loadModuleClass(Module.java:753)
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:247)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:410)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:116)
at java.base/java.lang.Class.getDeclaredMethods0(Native Method)
at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3167)
at java.base/java.lang.Class.getDeclaredMethods(Class.java:2310)
at deployment.interfaces2.ear//org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:467)
... 54 more
This error seems to be related to the class DefaultErrorAttributes
from Spring Framework's spring-boot-web
module. It appears that the class loader is unable to find the necessary class HandlerExceptionResolver
, leading to the NoClassDefFoundError
at runtime.
Additional Information:
- Spring Boot version: 2.7.11
- Wildfly version: 23
- Java version: 11
Here are the relevant dependencies from the pom.xml
file of the redacted-kafka-consumer
module:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>${servlet-api.version}</version>
<scope>provided</scope>
</dependency>
Any help or suggestions on how to resolve this issue would be greatly appreciated. Thank you!
答案1
得分: 1
"[加载DispatcherServlet的默认策略类错误](https://stackoverflow.com/a/20267074/6309)" 或 "[请告诉我Spring MVC错误](https://stackoverflow.com/a/45453371/6309)" 都指向模块之间的某个版本不一致。
因此,在构建war时,请仔细检查pom.xml加载的当前版本:
``` bash
mvn versions:display-dependency-updates
并检查是否有任何您可能考虑升级的更新:
mvn versions:display-dependency-updates
检查是否会在构建可交付物时,使用DependencyConvergence
规则来执行 enforcer 失败:
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<id>enforce</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<DependencyConvergence />
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
</project>
<details>
<summary>英文:</summary>
"[Error loading DispatcherServlet's default strategy class](https://stackoverflow.com/a/20267074/6309)" or "[Please advise to me that Spring MVC Error](https://stackoverflow.com/a/45453371/6309)" are both pointing to some version discrepancy between modules.
So double-check the current versions loaded by your pom.xml when building your war:
``` bash
mvn versions:display-dependency-updates
And check if there is any update you might want to consider upgrading to:
mvn versions:display-dependency-updates
Check if an enforcer would fail your build, using a DependencyConvergence
rule, when building your deliverable:
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<id>enforce</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<DependencyConvergence />
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
</project>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论