- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
今天我决定从最新的 Spring 4.3 官方版本切换到 Spring 5.0.0.M3,感谢他对 junit 多线程内置可能性的支持,而且 Flux 管理听起来确实很有趣。
花了一整天的时间摆弄我的 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 片段,但我不知道如何在这里打印整个堆栈跟踪,而不说明我必须在每行前面添加 4 个空格。
最佳答案
在尝试分享一个不起作用的示例时,我发现这个示例按预期工作。因此,我尝试注释我的配置类的某些部分并设法制作 Spring Boot。实际上问题如下:我的 Spring Configuration 类扩展了包含的 WebMvcConfigurationSupport 类
public void addInterceptors(InterceptorRegistryregistry);
出于某些自定义原因,我使用此方法添加了 customHandlerInterceptor。问题是这个拦截器是在另一个conf类中声明的bean,我曾经使用@Autowired注释在这个实际的类中获取它。由于我忽略的原因,这曾经适用于以前的 Spring 版本,但现在不再适用了...我通过在此类中声明此 bean 来获得与 @Autowired 注释不同的 bean,这给了我所有这些问题。启动现在运行良好,除了每次请求时我都会收到 404 错误:例如
2017-08-30 16:43:03.379 WARN 18584 --- [nio-8082-exec-4] o.s.web.servlet.PageNotFound:未找到带有 URI 的 HTTP 请求的映射 [/v1/admin/validate] 在 DispatcherServlet 中,名称为“dispatcherServlet”
编辑--
映射实际上有效,但在 Spring 4.3 中,它过去常常在每个端点名称之前考虑“/v1”,该参数是在 application.properties 中给出的,我认为它没有被考虑在内。新的 Spring 版本似乎尚不支持 swagger 文档插件,因为整个文档不会加载,而是在重定向时发送 404。除此之外,我的处理程序现在没有正确注册,但我想这是因为我最新的修改做错了一些事情,所以我需要先修复这个问题。
编辑 2 --
我在某处读到,在 Spring 5 中,您必须将“extends WebMvcConfigurerAdapter”替换为“extends WebMvcConfigurerSupport”类,因为第一个类已被弃用,但这对我来说不起作用,我必须实现 WebMvcConfigurer。现在一切都按预期正常工作(包括大摇大摆)。另外,要修改 contextPath,您必须在 application.properties 中修改此参数:“server.servlet.context-path”而不是最后一个支持的“server.contextPath”
关于java - Spring 5.0.0.M3 调用 ApplicationEventListener 时出错 : No ServletContext set - Exception encountered during context initialization,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45944388/
我有一个 JSP 网站,不是 Spring MVC,它有一个配置文件 web.xml。 我想要获取 web.xml 文件中的一些设置。 但是,我想从“源包”文件夹中的类中访问这些设置。 我知道我可以将
什么是ServletContext? 根据字面意思即Servlet上下文 服务器会为每一个工程创建一个对象,这个对象就是ServletContext对象,这个对象是 全局唯一的,工程内部的所
我有一个类别列表,这些类别需要存在于应用程序的ServletContext范围内,因为该列表将由每个 View 访问,并且不需要修改。 我尝试在BootStrap.groovy的init方法中设置一个
ServletContext 是否在请求期间更新。例如我有这个代码: public void action(@Context ServletContext context) { Thread.sl
我正在将一些JSF代码从一个项目迁移到另一个项目,突然在我的新项目中ServletContext.TEMPDIR值失败了。我已经遍历了大多数文件,但这是唯一的错误,我不确定该在哪里修复。 tempdi
我正在尝试从服务访问servletContext(应用程序上下文)到集成测试中。 以下是我尝试让它进入我的集成测试的方法: import org.codehaus.groovy.grails.web.
我有 .NET 背景,正在尝试一些 Java(Servlet/JSP)基础知识。在.NET中,我们有ViewState、Session、Application变量。据我所知,Application 变
属性 repository 返回 null。 public class BaseServlet extends HttpServlet { protected MyPersistentMana
因此,我正在尝试建立一个在应用程序的多次使用(页面访问)中保持持久的 Mongo 连接。我厌倦了测试期间建立的所有这些连接,并且我想通过拥有单个持久连接来使用正确的过程。最佳实践等等。 这是我所拥有的
我正在我的 ServletContext 中存储一个 HashMap 对象。但是多个请求线程正在读取和修改这个 HashMap。 因为我相信 ServletContext 对象在请求线程之间共享,所以
您能否解释一下如何在我的Application 的子类中获取ServletContext 实例?可能吗?我试过像下面的代码片段那样做,但它似乎不起作用 - ctx 未设置: import javax.
我正在尝试手动引导 dispatcherservlet 作为练习。代码是 ServletRegistration.Dynamic dispatcher = container.addServlet(
这里的前提是,我不允许在这个网站上使用JavaScript或Cookies。 但是,我不想在每项至少需要密码 15-30 分钟的基本任务中询问用户密码。 我也不喜欢将密码保存到临时文件中,以防程序死掉
如果我使用 ../,为什么 ServletContext#getRealPath() 不会返回正确的路径 此代码有效:- System.out.println(context.getRealPath(
我正在使用上下文来共享登录 session 。我使用 setAttibute 函数。我知道 HttpSession 具有设置最大超时时间的属性。 是否可以以类似的方式设置上下文属性? ServletC
ServletConfig 和 ServletContext 接口(interface)有什么区别? 最佳答案 ServletConfig 参数是为特定 servlet 指定的,其他 servlet
我想听听你的意见。我正在开发一个 Servlet,它必须签署发送到端点的请求。 为了避免从服务器的 keystore 文件中读取、加载它并获取私钥,我在实现 ServletContextListene
我正在寻找一种方法将一些数据从数据库加载到 HashMap 中,并使该映射可用于所有根资源类和一些其他提供程序类(更准确地说是 ContainerRequestFilter 的实现)。我找到并实现了一
是否可以使用此API获取远程资源:ServletContext.getResourceAsStream() 例如:ServletContext.getResourceAsStream("http://
我的 RemoteServiceServlet 的日志输出(GWT) 在使用 getServletContext().log("anything"); 时不会显示在日志文件或标准输出中 对于依赖注入(
我是一名优秀的程序员,十分优秀!