java - Spring java.lang.NoSuchMethodError : org. springframework.web.accept.PathExtensionContentNegotiationStrategy.getMediaTypes()Ljava/util/Map;

标签 java spring maven spring-boot spring-security

我在堆栈跟踪中收到以下错误。我刚刚执行了 Maven clean/rebuild 之后就开始出现此错误。 我尝试了其他类似问题的一些建议:Error creating bean with name defaultServletHandlerMappingError creating bean with name 'defaultServletHandlerMapping但没有一个解决方案有效。

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2017-01-12 18:34:49.883 ERROR 13404 --- [           main] o.s.boot.SpringApplication               : Application startup failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'resourceHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method 'resourceHandlerMapping' threw exception; nested exception is java.lang.NoSuchMethodError: org.springframework.web.accept.PathExtensionContentNegotiationStrategy.getMediaTypes()Ljava/util/Map;
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1128) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1023) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:751) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
at com.solambda.kronos.timesheet.TimesheetWebApplication.main(TimesheetWebApplication.java:60) [classes/:na]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method 'resourceHandlerMapping' threw exception; nested exception is java.lang.NoSuchMethodError: org.springframework.web.accept.PathExtensionContentNegotiationStrategy.getMediaTypes()Ljava/util/Map;
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
... 18 common frames omitted
Caused by: java.lang.NoSuchMethodError: org.springframework.web.accept.PathExtensionContentNegotiationStrategy.getMediaTypes()Ljava/util/Map;
at org.springframework.web.servlet.resource.ResourceHttpRequestHandler.initPathExtensionStrategy(ResourceHttpRequestHandler.java:307) ~[spring-webmvc-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.web.servlet.resource.ResourceHttpRequestHandler.afterSingletonsInstantiated(ResourceHttpRequestHandler.java:298) ~[spring-webmvc-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry.getHandlerMapping(ResourceHandlerRegistry.java:148) ~[spring-webmvc-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.resourceHandlerMapping(WebMvcConfigurationSupport.java:453) ~[spring-webmvc-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$EnableWebMvcConfiguration$$EnhancerBySpringCGLIB$$7d35fc5f.CGLIB$resourceHandlerMapping$40(<generated>) ~[spring-boot-autoconfigure-1.4.1.RELEASE.jar:1.4.1.RELEASE]
at org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$EnableWebMvcConfiguration$$EnhancerBySpringCGLIB$$7d35fc5f$$FastClassBySpringCGLIB$$a8ada992.invoke(<generated>) ~[spring-boot-autoconfigure-1.4.1.RELEASE.jar:1.4.1.RELEASE]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:356) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$EnableWebMvcConfiguration$$EnhancerBySpringCGLIB$$7d35fc5f.resourceHandlerMapping(<generated>) ~[spring-boot-autoconfigure-1.4.1.RELEASE.jar:1.4.1.RELEASE]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_101]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_101]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_101]
at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_101]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
... 19 common frames omitted

2017-01-12 18:34:49.885  INFO 13404 --- [DB4j\data\50718] ch.vorburger.mariadb4j.DB                : cleanupOnExit() ShutdownHook quietly deleting temporary DB data directory: C:\Users\Abhinay\AppData\Local\Temp\MariaDB4j\data\50718
2017-01-12 18:34:50.215  INFO 13404 --- [DB4j\data\50718] ch.vorburger.mariadb4j.DB                : cleanupOnExit() ShutdownHook quietly deleting temporary DB base directory: C:\Users\Abhinay\AppData\Local\Temp\MariaDB4j\base

这是我的主要类(class):

 @EnableAutoConfiguration
 @Configuration
 @Import({ TimesheetWebApplicationConfiguration.class,      EmbeddedDBConfiguration.class })

public class TimesheetWebApplication {
private static final Logger LOGGER = LoggerFactory.getLogger(TimesheetWebApplication.class);

@Autowired
private MissionInfoServiceClient missionServiceClient;

@Autowired
private UserCompanyContactServiceClientMockImpl userCompanyContactServiceClient;

@Autowired
TimesheetDao timesheetDao;

@Autowired
TimesheetInputDao timesheetInputDao;

@Autowired
TimesheetDayDao timesheetDayDao;

public static void main(final String[] args) {
    SpringApplication.run(TimesheetWebApplication.class, args);

}

@Bean
public ApplicationRunner runner(final Flyway flyway) {
    return args -> {
        if (args.containsOption("migrateDB")) {
            LOGGER.info("Executing database migrations");
            flyway.migrate();
        }

        if (args.containsOption("insertTestData")) {
            LOGGER.info("Inserting test data for local testing");
            // TODO
        }

         // populating data here 

    };
}

}

最佳答案

今天,我在 Spring-boot 1.5.1.RELEASE 上进行了测试,发现了同样的问题..

我发现,在SpringBoot 1.5.1.RELEASE中定义的spring-web spring-context是一个旧版本,然后我在我的pom.xml中定义了关于spring-web和spring-context的2个 Artifact ,以与其他spring保持同步-xx 的版本

只需输入流程:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>4.3.6.RELEASE</version>
    <exclusions>
        <exclusion>
            <artifactId>commons-logging</artifactId>
            <groupId>commons-logging</groupId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>4.3.6.RELEASE</version>
    <exclusions>
        <exclusion>
            <artifactId>commons-logging</artifactId>
            <groupId>commons-logging</groupId>
        </exclusion>
    </exclusions>
</dependency>

然后就可以正常工作了。

关于java - Spring java.lang.NoSuchMethodError : org. springframework.web.accept.PathExtensionContentNegotiationStrategy.getMediaTypes()Ljava/util/Map;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41629552/

相关文章:

java - 带有 iText 7 的 PDF 中的希腊字符

在 azure 管道上运行时 Spring @Value FileNotFound

java - 错误消息的顺序不正确

java - 我的 Spring MVC 配置有什么问题?

java - 不是抽象的,也不会覆盖抽象方法 actionPerforme

java - 如何在java代码中设置代理配置

java - 使用 Java 的 AWS ElastiCache Redis

java - 更新 mongoDB

java - 如何理解 Maven 依赖树

maven - 从本地Maven存储库获取.jar文件