2017-08-29 113 views
1

今天我決定從最新的Spring 4.3官方發佈版本切換到5.0.0.M3版本,這要感謝他支持junit多線程內置它的Flux gestion絕對聽起來很有趣。Spring 5.0.0.M3調用ApplicationEventListener時出錯:沒有ServletContext set - 在上下文初始化期間遇到異常

花了整整一天玩我的pom.xml試圖找出爲什麼它不起作用,我終於設法使它工作,至少我認爲,mvn測試命令運行良好,並輸出一個建築成功我所有的百次單元測試。 Altough應用程序不啓動,這讓我這個奇怪的錯誤:

017-08-29 18:22:08.196 INFO 19052 --- [   main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest) 
 
2017-08-29 18:22:08.197 INFO 19052 --- [   main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) 
 
2017-08-29 18:22:09.099 INFO 19052 --- [   main] b.a.s.AuthenticationManagerConfiguration : 
 

 
Using default security password: b5c2ef80-ab3e-4bec-91ba-c5e29b086018 
 

 
2017-08-29 18:22:09.509 INFO 19052 --- [   main] o.s.s.web.DefaultSecurityFilterChain  : Creating filter chain: NegatedRequestMatcher [requestMatcher=Ant [pattern='^/((authenticate)|(swagger-ui.html)|(webjars[/a-zA-Z.1-9-]{0,})){0,1}$']], [[email protected], org.springframework.secu[email protected]399f9da1, org.spring[email protected]63d7f239, [email protected]819, org.[email protected]59f79dd6, org.sp[email protected]180857ea, org.springframework.[email protected]9e1b62d, org.springfram[email protected]74258c18, o[email protected]627ba2cd, org[email protected]1e3fc5d4] 
 
2017-08-29 18:22:09.854 WARN 19052 --- [   main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'resourceHandlerMapping' defined in class path resource [org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.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.IllegalStateException: No ServletContext set 
 
2017-08-29 18:22:09.892 INFO 19052 --- [   main] o.apache.catalina.core.StandardService : Stopping service [Tomcat] 
 
2017-08-29 18:22:09.959 WARN 19052 --- [   main] o.s.b.c.e.EventPublishingRunListener  : Error calling ApplicationEventListener 
 

 
java.lang.ClassCastException: org.springframework.boot.context.event.ApplicationFailedEvent cannot be cast to org.springframework.boot.web.context.WebServerInitializedEvent 
 
\t at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:159) [spring-context-5.0.0.RC3.jar:5.0.0.RC3] 
 
\t at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) [spring-context-5.0.0.RC3.jar:5.0.0.RC3] 
 
\t at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127) [spring-context-5.0.0.RC3.jar:5.0.0.RC3] 
 
\t at org.springframework.boot.context.event.EventPublishingRunListener.finished(EventPublishingRunListener.java:114) [spring-boot-2.0.0.M3.jar:2.0.0.M3] 
 
\t at org.springframework.boot.SpringApplicationRunListeners.callFinishedListener(SpringApplicationRunListeners.java:79) [spring-boot-2.0.0.M3.jar:2.0.0.M3] 
 
\t at org.springframework.boot.SpringApplicationRunListeners.finished(SpringApplicationRunListeners.java:72) [spring-boot-2.0.0.M3.jar:2.0.0.M3] 
 
\t at org.springframework.boot.SpringApplication.handleRunFailure(SpringApplication.java:803) [spring-boot-2.0.0.M3.jar:2.0.0.M3] 
 
\t at org.springframework.boot.SpringApplication.run(SpringApplication.java:338) [spring-boot-2.0.0.M3.jar:2.0.0.M3] 
 
\t at io.swagger.Swagger2SpringBoot.main(Swagger2SpringBoot.java:44) [classes/:na] 
 
\t at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_101] 
 
\t at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_101] 
 
\t at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_101] 
 
\t at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_101] 
 
\t at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run(AbstractRunMojo.java:496) [spring-boot-maven-plugin-2.0.0.M3.jar:2.0.0.M3] 
 
\t at java.lang.Thread.run(Thread.java:745) [na:1.8.0_101] 
 

 
2017-08-29 18:22:09.990 INFO 19052 --- [   main] utoConfigurationReportLoggingInitializer : 
 

 
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled. 
 
2017-08-29 18:22:09.999 ERROR 19052 --- [   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/web/servlet/config/annotation/DelegatingWebMvcConfiguration.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.IllegalStateException: No ServletContext set 
 
\t at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:586) ~[spring-beans-5.0.0.RC3.jar:5.0.0.RC3] 
 
\t at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1261) ~[spring-beans-5.0.0.RC3.jar:5.0.0.RC3] 
 
\t at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1109) ~[spring-beans-5.0.0.RC3.jar:5.0.0.RC3] 
 
\t at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) ~[spring-beans-5.0.0.RC3.jar:5.0.0.RC3] 
 
\t at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:499) ~[spring-beans-5.0.0.RC3.jar:5.0.0.RC3] 
 
\t at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:312) ~[spring-beans-5.0.0.RC3.jar:5.0.0.RC3] 
 
\t at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.0.0.RC3.jar:5.0.0.RC3] 
 
\t at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310) ~[spring-beans-5.0.0.RC3.jar:5.0.0.RC3] 
 
\t at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[spring-beans-5.0.0.RC3.jar:5.0.0.RC3] 
 
\t at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755) ~[spring-beans-5.0.0.RC3.jar:5.0.0.RC3] 
 
\t at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:868) ~[spring-context-5.0.0.RC3.jar:5.0.0.RC3] 
 
\t at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.0.0.RC3.jar:5.0.0.RC3] 
 
\t at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:122) ~[spring-boot-2.0.0.M3.jar:2.0.0.M3] 
 
\t at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) ~[spring-boot-2.0.0.M3.jar:2.0.0.M3] 
 
\t at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:386) ~[spring-boot-2.0.0.M3.jar:2.0.0.M3] 
 
\t at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) ~[spring-boot-2.0.0.M3.jar:2.0.0.M3] 
 
\t at io.swagger.Swagger2SpringBoot.main(Swagger2SpringBoot.java:44) [classes/:na] 
 
\t at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_101] 
 
\t at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_101] 
 
\t at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_101] 
 
\t at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_101] 
 
\t at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run(AbstractRunMojo.java:496) [spring-boot-maven-plugin-2.0.0.M3.jar:2.0.0.M3] 
 
\t at java.lang.Thread.run(Thread.java:745) [na:1.8.0_101] 
 
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method 'resourceHandlerMapping' threw exception; nested exception is java.lang.IllegalStateException: No ServletContext set 
 
\t at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:182) ~[spring-beans-5.0.0.RC3.jar:5.0.0.RC3] 
 
\t at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:575) ~[spring-beans-5.0.0.RC3.jar:5.0.0.RC3] 
 
\t ... 22 common frames omitted 
 
Caused by: java.lang.IllegalStateException: No ServletContext set 
 
\t at org.springframework.util.Assert.state(Assert.java:73) ~[spring-core-5.0.0.RC3.jar:5.0.0.RC3] 
 
\t at org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.resourceHandlerMapping(WebMvcConfigurationSupport.java:479) ~[spring-webmvc-5.0.0.RC3.jar:5.0.0.RC3] 
 
\t at org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration$$EnhancerBySpringCGLIB$$e96afb94.CGLIB$resourceHandlerMapping$31(<generated>) ~[spring-webmvc-5.0.0.RC3.jar:5.0.0.RC3] 
 
\t at org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration$$EnhancerBySpringCGLIB$$e96afb94$$FastClassBySpringCGLIB$$cb32715e.invoke(<generated>) ~[spring-webmvc-5.0.0.RC3.jar:5.0.0.RC3] 
 
\t at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-5.0.0.RC3.jar:5.0.0.RC3] 
 
\t at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:360) ~[spring-context-5.0.0.RC3.jar:5.0.0.RC3] 
 
\t at org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration$$EnhancerBySpringCGLIB$$e96afb94.resourceHandlerMapping(<generated>) ~[spring-webmvc-5.0.0.RC3.jar:5.0.0.RC3] 
 
\t at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_101] 
 
\t at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_101] 
 
\t at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_101] 
 
\t at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_101] 
 
\t at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:155) ~[spring-beans-5.0.0.RC3.jar:5.0.0.RC3] 
 
\t ... 23 common frames omitted 
 

 
[WARNING] 
 
java.lang.reflect.InvocationTargetException 
 
\t at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
 
\t at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
 
\t at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
 
\t at java.lang.reflect.Method.invoke(Method.java:498) 
 
\t at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run(AbstractRunMojo.java:496) 
 
\t at java.lang.Thread.run(Thread.java:745) 
 
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'resourceHandlerMapping' defined in class path resource [org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.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.IllegalStateException: No ServletContext set 
 
\t at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:586) 
 
\t at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1261) 
 
\t at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1109) 
 
\t at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) 
 
\t at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:499) 
 
\t at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:312) 
 
\t at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) 
 
\t at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310) 
 
\t at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) 
 
\t at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755) 
 
\t at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:868) 
 
\t at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) 
 
\t at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:122) 
 
\t at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) 
 
\t at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:386) 
 
\t at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) 
 
\t at io.swagger.Swagger2SpringBoot.main(Swagger2SpringBoot.java:44) 
 
\t ... 6 more 
 
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method 'resourceHandlerMapping' threw exception; nested exception is java.lang.IllegalStateException: No ServletContext set 
 
\t at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:182) 
 
\t at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:575) 
 
\t ... 22 more 
 
Caused by: java.lang.IllegalStateException: No ServletContext set 
 
\t at org.springframework.util.Assert.state(Assert.java:73) 
 
\t at org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.resourceHandlerMapping(WebMvcConfigurationSupport.java:479) 
 
\t at org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration$$EnhancerBySpringCGLIB$$e96afb94.CGLIB$resourceHandlerMapping$31(<generated>) 
 
\t at org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration$$EnhancerBySpringCGLIB$$e96afb94$$FastClassBySpringCGLIB$$cb32715e.invoke(<generated>) 
 
\t at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) 
 
\t at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:360) 
 
\t at org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration$$EnhancerBySpringCGLIB$$e96afb94.resourceHandlerMapping(<generated>) 
 
\t at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
 
\t at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
 
\t at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
 
\t at java.lang.reflect.Method.invoke(Method.java:498) 
 
\t at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:155) 
 
\t ... 23 more 
 
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.0.0.M3:run (default-cli) on project whimtrip-api: An exception occurred while running. null: InvocationTargetException: Error creating bean with name 'resourceHandlerMapping' defined in class path resource [org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.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.IllegalStateException: No ServletContext set -> [Help 1] 
 

我發現了一些非常類似的錯誤,到這裏並通過谷歌搜索,但事情是它總是從與另一個無法用非常明確的消息啓動的bean發生錯誤。在我的情況下,它說servlet上下文沒有設置,我可以理解會有問題,但我不明白爲什麼它沒有設置?任何人都有線索?感謝您的未來幫助!

下面

是我的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 http://maven.apache.org/maven-v4_0_0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>****</groupId> 
<artifactId>**********</artifactId> 
<packaging>jar</packaging> 
<name>*****</name> 
<version>1.0.0</version> 
<properties> 
    <java.version>1.8</java.version> 
    <maven.compiler.source>${java.version}</maven.compiler.source> 
    <maven.compiler.target>${java.version}</maven.compiler.target> 
    <springfox-version>2.5.0</springfox-version> 
    <spring-core-version>5.0.0.RC3</spring-core-version> 
    <spring-modules-version>5.0.0.M3</spring-modules-version> 
    <spring-boot-version>2.0.0.M3</spring-boot-version> 
</properties> 
<repositories> 
    <repository> 
     <id>com.springsource.repository.bundles.release</id> 
     <name>SpringSource Enterprise Bundle Repository - SpringSource Bundle Releases</name> 
     <url>http://repository.springsource.com/maven/bundles/release</url> 
    </repository> 
    <repository> 
     <id>com.springsource.repository.bundles.external</id> 
     <name>SpringSource Enterprise Bundle Repository - External Bundle Releases</name> 
     <url>http://repository.springsource.com/maven/bundles/external</url> 
    </repository> 
    <repository> 
     <id>org.springframework.maven.release</id> 
     <name>Spring Maven Release Repository</name> 
     <url>http://repo.springsource.org/libs-release-local</url> 
     <releases><enabled>true</enabled></releases> 
     <snapshots><enabled>false</enabled></snapshots> 
    </repository> 
    <!-- For testing against latest Spring snapshots --> 
    <repository> 
     <id>org.springframework.maven.snapshot</id> 
     <name>Spring Maven Snapshot Repository</name> 
     <url>http://repo.springsource.org/libs-snapshot-local</url> 
     <releases><enabled>false</enabled></releases> 
     <snapshots><enabled>true</enabled></snapshots> 
    </repository> 
    <!-- For developing against latest Spring milestones --> 
    <repository> 
     <id>org.springframework.maven.milestone</id> 
     <name>Spring Maven Milestone Repository</name> 
     <url>http://repo.springsource.org/libs-milestone-local</url> 
     <snapshots><enabled>false</enabled></snapshots> 
    </repository> 
    <repository> 
     <snapshots> 
      <enabled>false</enabled> 
     </snapshots> 
     <id>central</id> 
     <name>milestone</name> 
     <url>https://repo.spring.io/milestone</url> 
    </repository> 

    <repository> 
     <id>mvnrepo2</id> 
     <name>mvnrepo2</name> 
     <layout>default</layout> 
     <url>http://central.maven.org/maven2</url> 
     <snapshots> 
      <enabled>false</enabled> 
     </snapshots> 
    </repository> 
</repositories> 


<pluginRepositories> 
    <pluginRepository> 
     <snapshots> 
      <enabled>false</enabled> 
     </snapshots> 
     <id>central-spring</id> 
     <name>milestone</name> 
     <url>https://repo.spring.io/milestone</url> 
    </pluginRepository> 
</pluginRepositories> 

<parent> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-parent</artifactId> 
    <!--<version>1.3.5.RELEASE</version>--> 
    <version>2.0.0.M3</version> 
</parent> 
<build> 
    <sourceDirectory>src/main/java</sourceDirectory> 


    <plugins> 
     <plugin> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-maven-plugin</artifactId> 
      <executions> 
       <execution> 
        <goals> 
         <goal>repackage</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 

     <plugin> 
      <groupId>org.avaje.ebeanorm</groupId> 
      <artifactId>avaje-ebeanorm-mavenenhancer</artifactId> 
      <version>4.7.1</version> 
      <executions> 
       <execution> 
        <id>main</id> 
        <phase>process-classes</phase> 
        <configuration> 
         <packages>api.whimtrip.model.**</packages> 
         <transformArgs>debug=2</transformArgs> 
        </configuration> 
        <goals> 
         <goal>enhance</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 




    </plugins> 

</build> 
<dependencies> 

    <!-- Spring libs --> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-web</artifactId> 
     <version>${spring-boot-version}</version> 
    </dependency> 


    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-core</artifactId> 
     <!--<version>4.3.8.RELEASE</version>--> 
     <version>${spring-core-version}</version> 
    </dependency> 


    <!--SpringFox dependencies --> 
    <dependency> 
     <groupId>io.springfox</groupId> 
     <artifactId>springfox-swagger2</artifactId> 
     <version>${springfox-version}</version> 
    </dependency> 
    <dependency> 
     <groupId>io.springfox</groupId> 
     <artifactId>springfox-swagger-ui</artifactId> 
     <version>${springfox-version}</version> 
    </dependency> 

    <!-- Convert objects to and from xml and json --> 
    <dependency> 
     <groupId>com.fasterxml.jackson.datatype</groupId> 
     <artifactId>jackson-datatype-joda</artifactId> 
    </dependency> 


    <!-- Date manipulation lib --> 
    <dependency> 
     <groupId>joda-time</groupId> 
     <artifactId>joda-time</artifactId> 
    </dependency> 


    <!-- War building dependencies --> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-tomcat</artifactId> 
     <scope>provided</scope> 
    </dependency> 


    <!-- Bean Validation API support --> 
    <dependency> 
     <groupId>javax.validation</groupId> 
     <artifactId>validation-api</artifactId> 
     <version>1.1.0.Final</version> 
    </dependency> 
    <!-- Ebean dependencies--> 

    <dependency> 
     <groupId>org.avaje.ebeanorm</groupId> 
     <artifactId>avaje-ebeanorm</artifactId> 
     <version>6.18.1</version> 
    </dependency> 

    <dependency> 
     <groupId>org.avaje</groupId> 
     <artifactId>ebean-spring</artifactId> 
     <version>2.8.1</version> 
    </dependency> 




    <!-- Security Bundles --> 
    <dependency> 
     <groupId>org.springframework.security</groupId> 
     <artifactId>spring-security-core</artifactId> 
     <!--<version>4.2.3.RELEASE</version>--> 
     <version>${spring-modules-version}</version> 
    </dependency> 


    <dependency> 
     <groupId>org.springframework.security</groupId> 
     <artifactId>spring-security-web</artifactId> 
     <!--<version>4.2.2.RELEASE</version>--> 
     <version>${spring-modules-version}</version> 
    </dependency> 


    <dependency> 
     <groupId>org.springframework.security</groupId> 
     <artifactId>spring-security-config</artifactId> 
     <!--<version>4.2.2.RELEASE</version>--> 
     <version>${spring-modules-version}</version> 
    </dependency> 



    <!-- Mail dependencies --> 

    <dependency> 
     <groupId>org.springframework.integration</groupId> 
     <artifactId>spring-integration-mail</artifactId> 
     <version>3.0.2.RELEASE</version> 
    </dependency> 

    <dependency> 
     <groupId>javax.activation</groupId> 
     <artifactId>activation</artifactId> 
     <version>1.1-rev-1</version> 
    </dependency> 

    <dependency> 
     <groupId>javax.mail</groupId> 
     <artifactId>mail</artifactId> 
     <version>1.4.3</version> 
    </dependency> 



    <!-- Tests libs --> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-test</artifactId> 
     <!--<version>4.3.8.RELEASE</version>--> 
     <version>${spring-modules-version}</version> 
     <scope>test</scope> 
    </dependency> 

    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>4.12</version> 
     <scope>test</scope> 
    </dependency> 


    <dependency> 
     <groupId>org.mockito</groupId> 
     <artifactId>mockito-core</artifactId> 
     <version>1.9.5</version> 
     <scope>test</scope> 
    </dependency> 

</dependencies> 


</project> 

PS:對不起,把日誌的JavaScript代碼,但我無法弄清楚如何打印整個堆棧跟蹤在這裏沒有它說我必須在每行前面添加4個空格。

+0

請問你能分享一個樣本,我們可以運行重現問題? –

+0

@ stephane-nicoll我可以嘗試在專用的環境中重現此操作,並將發送完成後,感謝您的答案! –

+0

@ stephane-nicoll我試圖在一個新的項目中使用相同的配置和相同的pom.xml重現這一點,除了我刪除了所有的bean和我的項目的核心,這樣只有配置被留在這裏,並且工作順利......我可能在另一個項目的IDE中有一些問題,讓我檢查所有這些 –

回答

1

雖然試圖分享一個非工作的例子,但我發現這一個按預期工作。因此,我試圖評論我的配置類的一些部分,並設法進行春季啓動。其實這個問題是以下幾點: 其擴展WebMvcConfigurationSupport類我的春天配置類包含

public void addInterceptors(InterceptorRegistry registry);

我用這個方法來添加一個customHandlerInterceptor爲一些自定義的原因。 問題是這個攔截器是一個在另一個conf類中聲明的bean,並且我使用@Autowired註解來獲取它在這個實際的類中。由於我忽略的原因,這個過去與以前的Spring版本一起工作,但現在它不再了......我設法通過在這個類中聲明這個bean給我所有這些問題來獲得這個bean,而不是從@Autowired註釋。引導現在運行良好,除了在每個請求我收到了404錯誤: 例如

2017-08-30 16:43:03.379 WARN 18584 --- [nio-8082-exec-4] o.s.web.servlet.PageNotFound : No mapping found for HTTP request with URI [/v1/admin/validate] in DispatcherServlet with name 'dispatcherServlet'

編輯 -

映射實際工作,但在Spring 4.3它曾經考慮「/v1「之前,這個參數是在application.properties中給出的,我沒有把它考慮進去。看起來swagger文檔插件在新的spring版本中還不被支持,因爲整個文檔只是不加載,而是在重定向時發送404。 除此之外,我的處理程序現在沒有正確註冊,但我想這是因爲我已經做了錯誤的最新修改,所以我需要先解決這個問題。

EDIT 2 -

我讀的地方,在Spring 5,你必須更換「擴展WebMvcConfigurerAdapter」,因爲第一個被棄用「擴展WebMvcConfigurerSupport」級,然而這並沒有爲工作我和我不得不實現WebMvcConfigurer。現在一切正常,如預期(包括招搖)。另外,要修改contextPath,你必須在你的application.properties中修改這個參數:「server.servlet.context-path」,而不是最後一個支持的「server.contextPath」

相關問題