Factory method 'mvcResourceUrlProvider' threw exception; nested exception is java.lang.NoSuchFieldError: defaultInstance

huangapple go评论71阅读模式
英文:

Factory method 'mvcResourceUrlProvider' threw exception; nested exception is java.lang.NoSuchFieldError: defaultInstance

问题

我刚刚升级到Spring Boot 2.3.4.RELEASE,现在在尝试启动应用程序时遇到以下错误:

2020-10-12 10:16:23.870 ERROR 651 --- [           main] o.s.boot.SpringApplication               : 应用程序启动失败

org.springframework.beans.factory.UnsatisfiedDependencyException: 在 URL [jar:file: repository/io/springfox/springfox-spring-webmvc/3.0.0/springfox-spring-webmvc-3.0.0.jar!/springfox/documentation/spring/web/plugins/WebMvcRequestHandlerProvider.class] 中定义的名为 'webMvcRequestHandlerProvider' 的 bean 创建错误:通过构造函数参数 2 表达的不满足的依赖项;嵌套异常是 org.springframework.beans.factory.UnsatisfiedDependencyException: 在类路径资源 [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class] 中定义的名为 'requestMappingHandlerMapping' 的 bean 创建错误:通过方法 'requestMappingHandlerMapping' 参数 2 表达的不满足的依赖项;嵌套异常是 org.springframework.beans.factory.BeanCreationException: 在类路径资源 [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class] 中定义的名为 'mvcResourceUrlProvider' 的 bean 创建错误:通过工厂方法实例化 bean 失败;嵌套异常是 org.springframework.beans.BeanInstantiationException: 实例化 [org.springframework.web.servlet.resource.ResourceUrlProvider] 失败:工厂方法 'mvcResourceUrlProvider' 抛出异常;嵌套异常是 java.lang.NoSuchFieldError: defaultInstance
	at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:797) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:227) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1356) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1203) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:556) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]

是否有人遇到相同的错误? 问候。

英文:

I just upgraded to spring boot 2.3.4.RELEASE and now i have to following error when i try to start the application:

    2020-10-12 10:16:23.870 ERROR 651 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'webMvcRequestHandlerProvider' defined in URL [jar:file: repository/io/springfox/springfox-spring-webmvc/3.0.0/springfox-spring-webmvc-3.0.0.jar!/springfox/documentation/spring/web/plugins/WebMvcRequestHandlerProvider.class]: Unsatisfied dependency expressed through constructor parameter 2; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Unsatisfied dependency expressed through method 'requestMappingHandlerMapping' parameter 2; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mvcResourceUrlProvider' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.resource.ResourceUrlProvider]: Factory method 'mvcResourceUrlProvider' threw exception; nested exception is java.lang.NoSuchFieldError: defaultInstance
	at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:797) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:227) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1356) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1203) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:556) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]

did somebody have the same errors?
regards

答案1

得分: 1

遇到了相同的问题。问题是 org.springframework.web.util.UrlPathHelper 类在 spring-web.jar 中缺少了 defaultInstance 字段。

在我的情况下,当升级到 spring-boot 2.3.12.RELEASE 时,问题浮现出来。原因是因为我的一些传递依赖项中将 spring.version 属性设置为旧版本的 spring-web。版本应该从 spring-boot-starter-parent 中继承。我移除了这个属性来修复这个问题。

请检查是否有类似的操作。你可以使用 Maven 的 dependency 插件查看项目所有依赖项和版本的树状图:

mvn dependency:tree
英文:

Ran into the same issue. The issue is that the org.springframework.web.util.UrlPathHelper class of spring-web.jar is missing the defaultInstance field.

In my case, the problem surfaced when upgrading to spring-boot, 2.3.12.RELEASE. The cause was because one of my transitive dependencies had a spring.version property set to an old version of spring-web. The version should be inherited from the spring-boot-starter-parent. I removed the property to fix the issue.

Check to see if you are doing something similar. You can view a tree of all your project's dependencies and versions using the maven dependency plugin:

mvn dependency:tree

答案2

得分: 0

我不得不添加springframework-bom依赖,以便所有的Spring依赖项得到正确的更新!

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-framework-bom</artifactId>
    <version>${spring-framework.version}</version>
    <type>pom</type>
    <scope>import</scope>
</dependency>

没有它,spring-beansspring-aop以及许多其他内容都没有被更新。

英文:

i had to add the springframework-bom dependency in order that all spring dependencies got updated correctly!

&lt;dependency&gt;
            &lt;groupId&gt;org.springframework&lt;/groupId&gt;
            &lt;artifactId&gt;spring-framework-bom&lt;/artifactId&gt;
            &lt;version&gt;${spring-framework.version}&lt;/version&gt;
            &lt;type&gt;pom&lt;/type&gt;
            &lt;scope&gt;import&lt;/scope&gt;
        &lt;/dependency&gt;

without it, spring-beans, spring-aop and a lot more were not updated

huangapple
  • 本文由 发表于 2020年10月12日 16:30:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/64314256.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定