报错信息






org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'resourceHandlerMapping' defined in class path resource [org/svnadmin/MvcConfig.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.instantiate(ConstructorResolver.java:658) ~[spring-beans-5.3.9.jar!/:5.3.9]


        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:638) ~[spring-beans-5.3.9.jar!/:5.3.9]


        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1334) ~[spring-beans-5.3.9.jar!/:5.3.9]


        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1177) ~[spring-beans-5.3.9.jar!/:5.3.9]


        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:564) ~[spring-beans-5.3.9.jar!/:5.3.9]


        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:524) ~[spring-beans-5.3.9.jar!/:5.3.9]


        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.9.jar!/:5.3.9]


        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.9.jar!/:5.3.9]


        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.9.jar!/:5.3.9]


        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.9.jar!/:5.3.9]


        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:944) ~[spring-beans-5.3.9.jar!/:5.3.9]


        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[spring-context-5.3.9.jar!/:5.3.9]


        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.9.jar!/:5.3.9]


        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:144) ~[spring-boot-2.4.10.jar!/:2.4.10]


        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:771) ~[spring-boot-2.4.10.jar!/:2.4.10]


        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:763) ~[spring-boot-2.4.10.jar!/:2.4.10]


        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:438) ~[spring-boot-2.4.10.jar!/:2.4.10]


        at org.springframework.boot.SpringApplication.run(SpringApplication.java:339) ~[spring-boot-2.4.10.jar!/:2.4.10]


        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1329) ~[spring-boot-2.4.10.jar!/:2.4.10]


        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1318) ~[spring-boot-2.4.10.jar!/:2.4.10]


        at org.svnadmin.SVNAdminApplication.main(SVNAdminApplication.java:17) ~[classes!/:1.0.0]


        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104) ~[na:na]


        at java.base/java.lang.reflect.Method.invoke(Method.java:577) ~[na:na]


        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) ~[svnadmin-boot2.jar:1.0.0]


        at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) ~[svnadmin-boot2.jar:1.0.0]


        at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) ~[svnadmin-boot2.jar:1.0.0]


        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:58) ~[svnadmin-boot2.jar:1.0.0]


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:185) ~[spring-beans-5.3.9.jar!/:5.3.9]


        at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653) ~[spring-beans-5.3.9.jar!/:5.3.9]


        ... 26 common frames omitted


Caused by: java.lang.IllegalStateException: No ServletContext set


        at org.springframework.util.Assert.state(Assert.java:76) ~[spring-core-5.3.9.jar!/:5.3.9]


        at org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.resourceHandlerMapping(WebMvcConfigurationSupport.java:591) ~[spring-webmvc-5.3.9.jar!/:5.3.9]


        at org.svnadmin.MvcConfig$$EnhancerBySpringCGLIB$$16751b51.CGLIB$resourceHandlerMapping$40(<generated>) ~[classes!/:1.0.0]


        at org.svnadmin.MvcConfig$$EnhancerBySpringCGLIB$$16751b51$$FastClassBySpringCGLIB$$cccb696d.invoke(<generated>) ~[classes!/:1.0.0]


        at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) ~[spring-core-5.3.9.jar!/:5.3.9]


        at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331) ~[spring-context-5.3.9.jar!/:5.3.9]


        at org.svnadmin.MvcConfig$$EnhancerBySpringCGLIB$$16751b51.resourceHandlerMapping(<generated>) ~[classes!/:1.0.0]


        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104) ~[na:na]


        at java.base/java.lang.reflect.Method.invoke(Method.java:577) ~[na:na]


        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.3.9.jar!/:5.3.9]


        ... 27 common frames omitted





解决办法

检查项目中是否有配置spring.main.web-application-type=none,去掉这个配置,或者修改值为servlet

原因分析

SpringApplication的应用类型被指定未None