【问题标题】:Spring 5.0.0.M3 Error calling ApplicationEventListener : No ServletContext set - Exception encountered during context initializationSpring 5.0.0.M3 调用 ApplicationEventListener 时出错:未设置 ServletContext - 上下文初始化期间遇到异常
【发布时间】:2017-08-29 16:46:48
【问题描述】:

今天我决定从最新的 Spring 4.3 官方版本切换到 Spring 5.0.0.M3,感谢他对 junit 多线程内置可能性的支持,而且 Flux gestion 听起来确实很有趣。

在玩了一整天我的 pom.xml 试图弄清楚为什么它不起作用之后,我终于设法让它工作了,至少我认为 mvn test 命令运行良好并为所有人输出 BUILD SUCCESS我的数百个单元测试。尽管应用程序无法启动,但它给了我这个奇怪的错误:

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}$']], [io.swagger.security.AuthenticationTokenProcessingFilter@7caf14a2, org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@399f9da1, org.springframework.security.web.context.SecurityContextPersistenceFilter@63d7f239, org.springframework.security.web.header.HeaderWriterFilter@14cf6819, org.springframework.security.web.authentication.logout.LogoutFilter@59f79dd6, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@180857ea, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@9e1b62d, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@74258c18, org.springframework.security.web.session.SessionManagementFilter@627ba2cd, org.springframework.security.web.access.ExceptionTranslationFilter@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
	at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:159) [spring-context-5.0.0.RC3.jar:5.0.0.RC3]
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) [spring-context-5.0.0.RC3.jar:5.0.0.RC3]
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127) [spring-context-5.0.0.RC3.jar:5.0.0.RC3]
	at org.springframework.boot.context.event.EventPublishingRunListener.finished(EventPublishingRunListener.java:114) [spring-boot-2.0.0.M3.jar:2.0.0.M3]
	at org.springframework.boot.SpringApplicationRunListeners.callFinishedListener(SpringApplicationRunListeners.java:79) [spring-boot-2.0.0.M3.jar:2.0.0.M3]
	at org.springframework.boot.SpringApplicationRunListeners.finished(SpringApplicationRunListeners.java:72) [spring-boot-2.0.0.M3.jar:2.0.0.M3]
	at org.springframework.boot.SpringApplication.handleRunFailure(SpringApplication.java:803) [spring-boot-2.0.0.M3.jar:2.0.0.M3]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:338) [spring-boot-2.0.0.M3.jar:2.0.0.M3]
	at io.swagger.Swagger2SpringBoot.main(Swagger2SpringBoot.java:44) [classes/:na]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_101]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_101]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_101]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_101]
	at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run(AbstractRunMojo.java:496) [spring-boot-maven-plugin-2.0.0.M3.jar:2.0.0.M3]
	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
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:586) ~[spring-beans-5.0.0.RC3.jar:5.0.0.RC3]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1261) ~[spring-beans-5.0.0.RC3.jar:5.0.0.RC3]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1109) ~[spring-beans-5.0.0.RC3.jar:5.0.0.RC3]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) ~[spring-beans-5.0.0.RC3.jar:5.0.0.RC3]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:499) ~[spring-beans-5.0.0.RC3.jar:5.0.0.RC3]
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:312) ~[spring-beans-5.0.0.RC3.jar:5.0.0.RC3]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.0.0.RC3.jar:5.0.0.RC3]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310) ~[spring-beans-5.0.0.RC3.jar:5.0.0.RC3]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[spring-beans-5.0.0.RC3.jar:5.0.0.RC3]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755) ~[spring-beans-5.0.0.RC3.jar:5.0.0.RC3]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:868) ~[spring-context-5.0.0.RC3.jar:5.0.0.RC3]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.0.0.RC3.jar:5.0.0.RC3]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:122) ~[spring-boot-2.0.0.M3.jar:2.0.0.M3]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) ~[spring-boot-2.0.0.M3.jar:2.0.0.M3]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:386) ~[spring-boot-2.0.0.M3.jar:2.0.0.M3]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) ~[spring-boot-2.0.0.M3.jar:2.0.0.M3]
	at io.swagger.Swagger2SpringBoot.main(Swagger2SpringBoot.java:44) [classes/:na]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_101]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_101]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_101]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_101]
	at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run(AbstractRunMojo.java:496) [spring-boot-maven-plugin-2.0.0.M3.jar:2.0.0.M3]
	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
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:182) ~[spring-beans-5.0.0.RC3.jar:5.0.0.RC3]
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:575) ~[spring-beans-5.0.0.RC3.jar:5.0.0.RC3]
	... 22 common frames omitted
Caused by: java.lang.IllegalStateException: No ServletContext set
	at org.springframework.util.Assert.state(Assert.java:73) ~[spring-core-5.0.0.RC3.jar:5.0.0.RC3]
	at org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.resourceHandlerMapping(WebMvcConfigurationSupport.java:479) ~[spring-webmvc-5.0.0.RC3.jar:5.0.0.RC3]
	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]
	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]
	at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-5.0.0.RC3.jar:5.0.0.RC3]
	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:360) ~[spring-context-5.0.0.RC3.jar:5.0.0.RC3]
	at org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration$$EnhancerBySpringCGLIB$$e96afb94.resourceHandlerMapping(<generated>) ~[spring-webmvc-5.0.0.RC3.jar:5.0.0.RC3]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_101]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_101]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_101]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_101]
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:155) ~[spring-beans-5.0.0.RC3.jar:5.0.0.RC3]
	... 23 common frames omitted

[WARNING] 
java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run(AbstractRunMojo.java:496)
	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
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:586)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1261)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1109)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:499)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:312)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:868)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:122)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:386)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:327)
	at io.swagger.Swagger2SpringBoot.main(Swagger2SpringBoot.java:44)
	... 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
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:182)
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:575)
	... 22 more
Caused by: java.lang.IllegalStateException: No ServletContext set
	at org.springframework.util.Assert.state(Assert.java:73)
	at org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.resourceHandlerMapping(WebMvcConfigurationSupport.java:479)
	at org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration$$EnhancerBySpringCGLIB$$e96afb94.CGLIB$resourceHandlerMapping$31(<generated>)
	at org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration$$EnhancerBySpringCGLIB$$e96afb94$$FastClassBySpringCGLIB$$cb32715e.invoke(<generated>)
	at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:360)
	at org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration$$EnhancerBySpringCGLIB$$e96afb94.resourceHandlerMapping(<generated>)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:155)
	... 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 sn-p 放置,但我无法弄清楚如何在此处打印整个堆栈跟踪,而不是说我必须在每行前面添加 4 个空格。

【问题讨论】:

  • 您能否分享一个我们可以运行以重现问题的示例?
  • @stephane-nicoll 我可以尝试在专用环境中重现此内容,完成后将发送此内容,谢谢您的回答!
  • @stephane-nicoll 我试图在一个具有相同配置和相同 pom.xml 的新项目中重现此问题,但我删除了所有 bean 和项目的核心,以便只留下配置和它工作顺利...我的 IDE 在另一个项目中可能有问题,让我检查所有这些

标签: java spring maven spring-mvc


【解决方案1】:

在尝试分享一个无效的示例时,我发现这个示例按预期工作。因此,我尝试评论我的配置类的某些部分并设法使弹簧启动。实际上问题如下: 我的 Spring Configuration 类扩展了 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 中给出的,我想它没有考虑到。新的 Spring 版本似乎还不支持 swagger 文档插件,因为整个文档没有加载,而是在重定向时发送 404。 除此之外,我的处理程序现在没有正确注册,但我想这是因为我的最新修改做错了什么,所以我需要先修复这个问题。

编辑 2 --

我在某处读到,在 Spring 5 中,您必须将“扩展 WebMvcConfigurerAdapter”替换为“扩展 WebMvcConfigurerSupport”类,因为第一个类已被弃用,但这对我不起作用,我必须改为实现 WebMvcConfigurer。现在一切都按预期工作正常(包括招摇)。此外,要修改 contextPath,您必须在 application.properties 中修改此参数:“server.servlet.context-path”而不是最后一个支持的“server.contextPath”

【讨论】:

  • 嗨 Louis,你的意思是 WebMvcConfigurationSupport 吗?
  • 实际上是@Sofiane,是WebMvcConfigurer 终于为我工作了:)
  • "但是这对我不起作用,我不得不实现 WebMvcConfigurer。" -> 你救了我的命,伙计们!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-11-04
  • 1970-01-01
  • 2018-09-08
  • 1970-01-01
  • 1970-01-01
  • 2020-05-03
  • 2018-01-26
相关资源
最近更新 更多