工厂方法“mvcResourceUrlProvider”引发异常;嵌套异常为java.lang.NoSuchFieldError:默认示例

1szpjjfi  于 2023-01-24  发布在  Java
关注(0)|答案(3)|浏览(529)

我刚刚升级到Sping Boot 2.3.4.RELEASE,现在我必须在尝试启动应用程序时遵循错误:

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]

有人犯过同样的错误吗?问候

nlejzf6q

nlejzf6q1#

遇到了同样的问题。问题是spring-web.jar的org.springframework.web.util.UrlPathHelper类缺少defaultInstance字段。
在我的例子中,问题是在升级到spring-boot 2.3.12.RELEASE时出现的。原因是我的一个可传递依赖项将spring.version属性设置为旧版本的spring-web。该版本应该从spring-boot-starter-parent继承。我删除了该属性以修复该问题。
检查一下你是否在做类似的事情,你可以使用maven dependency插件查看你的项目的所有依赖项和版本树:
mvn dependency:tree

zsohkypk

zsohkypk2#

我不得不添加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-beans,spring-aop和更多的东西就不会更新

r8xiu3jd

r8xiu3jd3#

我有一个类似的错误。我试图添加依赖项,仍然是同样的错误。有人能帮助这个吗?
junit test cases creating errors for when spring boot application migrated from 2.6.6 to 2.7.7. junit5 is used

相关问题