简体   繁体   English

SpringBoot BeanCreationException:创建名为“requestMappingHandlerAdapter”的 bean 时出错 原因:java.lang.NoSuchFieldError:defaultInstance

[英]SpringBoot BeanCreationException: Error creating bean with name 'requestMappingHandlerAdapter' Caused by: java.lang.NoSuchFieldError: defaultInstance

I have a SpringBoot + Maven project with JPA. When tring to run the application I got the following error stack.我有一个带有 JPA 的 SpringBoot + Maven 项目。当尝试运行该应用程序时,我得到以下错误堆栈。

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerAdapter' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Invocation of init method failed; org.springframework.beans.factory.BeanCreationException:在 class 路径资源 [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class] 中创建名称为“requestMappingHandlerAdapter”的 bean 时出错:调用 init 方法失败; nested exception is java.lang.NoSuchFieldError: defaultInstance at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1794) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.88213嵌套的异常是 java.lang.NoSuchFieldError: defaultInstance at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1794) ~[spring-beans-5.2.9.RELEASE.88201ASE.88201287 ] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE] 在 org.springframework.beans.factory .support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516)~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE] 在org.springframework.beans.factory.support.AbstractBeanFactory.lambda$ (AbstractBeanFactory.java:324) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE] 在 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.88213 246945888:234) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:897) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879) ~[spring-context-5.2.9.RELEASE.jar:5.2.9.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551) ~[spring-context-5.2.9.RELEASE.jar:5.2. 246945888:234) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE] 在 org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans -5.2.9.RELEASE.jar:5.2.9.RELEASE] 在 org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.9.RELEASE.jar: 5.2.9.RELEASE] 在 org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:897) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE] 在 org. springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879) ~[spring-context-5.2.9.RELEASE.jar:5.2.9.RELEASE] 在 org.springframework.context.support.AbstractApplicationContext.refreshApplicationContext(AbstractApplicationContext.refreshApplicationContext .java:551) ~[spring-context-5.2.9.RELEASE.jar:5.2。 9.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) ~[spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) [spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) [spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) [spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE] at org.springframework.boot.Sp 9.RELEASE] 在 org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) ~[spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE] 在 org. springframework.boot.SpringApplication.refresh(SpringApplication.java:758) [spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE] 在 org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) [spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE] 在 org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.3.4.RELEASE.jar:2.3 .4.RELEASE] 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE] 在 org.springframework.boot.SpringApplication。在 org.springframework.boot.Sp 运行(SpringApplication.java:1237)[spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE] ringApplication.run(SpringApplication.java:1226) [spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE] at com.pasindu.dockerexample.DockerExampleApplication.main(DockerExampleApplication.java:14) [classes/:na] Caused by: java.lang.NoSuchFieldError: defaultInstance at org.springframework.web.servlet.mvc.method.annotation.ServletCookieValueMethodArgumentResolver.(ServletCookieValueMethodArgumentResolver.java:40) ~[spring-webmvc-5.2.9.RELEASE.jar:5.2.9.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.getDefaultArgumentResolvers(RequestMappingHandlerAdapter.java:648) ~[spring-webmvc-5.2.9.RELEASE.jar:5.2.9.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.afterPropertiesSet(RequestMappingHandlerAdapter.java:561) ~[spring-webmvc-5.2.9.RELEASE.jar:5.2.9.RELEASE] at or ringApplication.run(SpringApplication.java:1226) [spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE] 在 com.pasindu.dockerexample.DockerExampleApplication.main(DockerExampleApplication.8821324:6:9458)8 na] Caused by: java.lang.NoSuchFieldError: defaultInstance at org.springframework.web.servlet.mvc.method.annotation.ServletCookieValueMethodArgumentResolver.(ServletCookieValueMethodArgumentResolver.java:40) ~[spring-webmvc-5.2.9.RELEASE.jar: 5.2.9.RELEASE] 在 org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.getDefaultArgumentResolvers(RequestMappingHandlerAdapter.java:648)~[spring-webmvc-5.2.9.RELEASE5.882020878: ] 在 org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.afterPropertiesSet(RequestMappingHandlerAdapter.java:561) ~[spring-webmvc-5.2.9.RELEASE.jar:5.2.9.RELEASE] 或。 g.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1853) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1790) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]... 17 common frames omitted Process finished with exit code 1在 org.springframework.supportbeans.factory .AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1790) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]... 省略了 17 个常见帧进程已完成,退出代码为 1

Below is my pom.xml file.下面是我的 pom.xml 文件。

 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
 <modelVersion>4.0.0</modelVersion>
 <parent>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-parent</artifactId>
     <version>2.3.4.RELEASE</version>
     <relativePath/> <!-- lookup parent from repository -->
 </parent>
 <groupId>com.demo</groupId>
 <artifactId>docker-example</artifactId>
 <version>0.0.1-SNAPSHOT</version>
 <name>docker-example</name>
 <description>Docker Example</description>

 <properties>
     <java.version>1.8</java.version>
 </properties>

 <dependencies>
     <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter</artifactId>
     </dependency>
     <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-web</artifactId>
     </dependency>
     <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-test</artifactId>
         <scope>test</scope>
         <exclusions>
             <exclusion>
                 <groupId>org.junit.vintage</groupId>
                 <artifactId>junit-vintage-engine</artifactId>
             </exclusion>
         </exclusions>
     </dependency>
     <dependency>
         <groupId>org.springframework</groupId>
         <artifactId>spring-web</artifactId>
         <version>5.2.8.RELEASE</version>
     </dependency>
     <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
     <dependency>
         <groupId>org.projectlombok</groupId>
         <artifactId>lombok</artifactId>
         <version>1.18.12</version>
         <scope>provided</scope>
     </dependency>
     <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-data-jpa</artifactId>
     </dependency>
     <dependency>
         <groupId>mysql</groupId>
         <artifactId>mysql-connector-java</artifactId>
         <version>8.0.18</version>
     </dependency>
 </dependencies>

 <build>
     <finalName>app</finalName>
     <plugins>
         <plugin>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-maven-plugin</artifactId>
         </plugin>
     </plugins>
 </build>
</project>

Any idea of how to fix this?知道如何解决这个问题吗?

The problem described is related to conflicts between different Maven dependencies.描述的问题与不同的 Maven 依赖之间的冲突有关。 I've had the same problem while trying to use the latest version of Spring Boot with Apache Camel.我在尝试将最新版本的 Spring Boot 与 Apache Camel 一起使用时遇到了同样的问题。

After analyzing the dependency tree, it turned out that the version of spring-webmvc was 5.2.9, while all other spring dependencies were of version 5.2.8.分析依赖树后发现spring-webmvc的版本是5.2.9,而其他spring个依赖都是5.2.8版本。

In my case, I have solved the problem by using a newer version of camel-spring-boot-dependencies (3.6.0, unlike previously used 3.5.0).就我而言,我已经通过使用更新版本的 camel-spring-boot-dependencies(3.6.0,与之前使用的 3.5.0 不同)解决了这个问题。

Found the solution.找到了解决方案。

In my pom.xml there were two dependencies like在我的 pom.xml 中有两个依赖项,例如

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

<dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>5.2.8.RELEASE</version>
</dependency>

What I did was removed the spring-web dependency and reloaded all Maven Plugins and tried running the project again.我所做的是删除spring-web依赖项并重新加载所有 Maven 插件并尝试再次运行该项目。

It was successful.它是成功的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 org.springframework.beans.factory.BeanCreationException 引起:java.lang.NoSuchFieldError: NULL - org.springframework.beans.factory.BeanCreationException Caused by : java.lang.NoSuchFieldError: NULL Spring:java.lang.NoSuchFieldError:IMPORT_BEAN_NAME_GENERATOR - Spring: java.lang.NoSuchFieldError: IMPORT_BEAN_NAME_GENERATOR 引起原因:java.lang.NoSuchFieldError:ruleMemo - Caused by: java.lang.NoSuchFieldError: ruleMemo 引起原因:java.lang.NoSuchFieldError:NULL - Caused by: java.lang.NoSuchFieldError: NULL 正在创建CA…意外错误java.lang.NoSuchFieldError:BasicConstraints - Creating CA… Unexpected Error java.lang.NoSuchFieldError: BasicConstraints 创建名为“requestMappingHandlerAdapter”的 bean 时出错 - Error creating bean with name 'requestMappingHandlerAdapter' 使用java.lang.NoSuchFieldError创建UnfoldingMap实例:质量错误 - Creating UnfoldingMap instance with java.lang.NoSuchFieldError: quality error 工厂方法“mvcResourceUrlProvider”抛出异常; 嵌套异常是 java.lang.NoSuchFieldError: defaultInstance - Factory method 'mvcResourceUrlProvider' threw exception; nested exception is java.lang.NoSuchFieldError: defaultInstance 原因:java.lang.NoSuchFieldError:将应用程序部署到Tomcat时为NULL - Caused by: java.lang.NoSuchFieldError: NULL while deploying application to Tomcat 造成原因:java.lang.NoSuchFieldError:android.support.v7.appcompat - Caused by: java.lang.NoSuchFieldError: android.support.v7.appcompat
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM