2017-01-13 2 views
0

Je reçois l'erreur suivante comme dans la trace de la pile. Je viens de faire le nettoyage/reconstruction de Maven par la suite commencé à obtenir cette erreur. J'ai essayé quelques-unes des suggestions d'autres questions similaires: Error creating bean with name defaultServletHandlerMapping et Error creating bean with name 'defaultServletHandlerMapping mais aucune de la solution n'a fonctionné.Spring java.lang.NoSuchMethodError: org.springframework.web.accept.PathExtensionContentNegotiationStrategy.getMediaTypes() Ljava/util/Carte;

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 

Voici ma classe principale:

@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 

    }; 
} 

}

+0

Vous mélangez les versions de printemps 4.3.2 et 4.3.3 ne mélangez jamais des bocaux de versions différentes. Fondamentalement, corrigez vos dépendances. –

+0

Je viens d'ajouter la dépendance dans maven et elle les récupère automatiquement. spring-web et quelques autres paquets de printemps sont sur la version 4.3.2. Qu'est-ce que vous proposez de faire? –

+0

apparemment ils ne sont pas ... Donc vous devez spécifier une version différente où. Ajoutez le pom à votre question. Votre trace de pile indique clairement que vous utilisez 'spring-context-4.3.2' et' spring-mvc-4.3.3' ceux-ci ne correspondent pas. –

Répondre

1

Aujourd'hui, j'ai un test sur 1.5.1.RELEASE Spring-boot, et je prends le même problème ..

J'ai trouvé, dans SpringBoot 1.5.1.RELEASE défini spring-web spring-context était une ancienne version, puis j'ai défini 2 artefact sur spring-web et spring-context dans mon pom.xml pour suivre le rythme avec d'autres printemps -xx's ve rsion

juste flux de type:

<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> 

il fonctionne bien.

1

J'ai rencontré la même erreur que l'OP lorsque j'essayais d'utiliser Spring Boot v1.5.2 dans mon application. Dans le fichier POM, aucune des versions Spring JAR n'a été substituée à l'exception de la dépendance Spring Web.

Avant:

<parent> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-parent</artifactId> 
     <version>1.5.2.RELEASE</version> 
    </parent> 
    <dependencies> 
     . 
     . 
     . 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-web</artifactId> 
      <version>4.3.2.RELEASE</version> 
     </dependency> 
     . 
     . 
     . 
    </dependencies> 

J'ai enlevé l'élément version de la dépendance Web du printemps. Cela a garanti que tous les artefacts Spring étaient sur la version 4.3.7, et l'exception NoSuchMethodError n'apparaissait plus au démarrage de l'application.

Après:

<parent> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-parent</artifactId> 
     <version>1.5.2.RELEASE</version> 
    </parent> 
    <dependencies> 
     . 
     . 
     . 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-web</artifactId> 
     </dependency> 
     . 
     . 
     . 
    </dependencies>