2015-09-24 3 views
1

Я запускаю простое настольное приложение с помощью Spring BOOT. Ниже стек ошибка:Ошибка с Spring BOOT

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultServletHandlerMapping' 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 'defaultServletHandlerMapping' threw exception; nested exception is java.lang.IllegalArgumentException: A ServletContext is required to configure default servlet handling 
 
\t at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) 
 
\t at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1119) 
 
\t at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1014) 
 
\t at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504) 
 
\t at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) 
 
\t at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) 
 
\t at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) 
 
\t at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) 
 
\t at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) 
 
\t at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755) 
 
\t at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757) 
 
\t at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480) 
 
\t at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686) 
 
\t at org.springframework.boot.SpringApplication.run(SpringApplication.java:320) 
 
\t at com.pb.relay.RelayDesktopApp.main(RelayDesktopApp.java:25) 
 
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method 'defaultServletHandlerMapping' threw exception; nested exception is java.lang.IllegalArgumentException: A ServletContext is required to configure default servlet handling 
 
\t at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) 
 
\t at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) 
 
\t ... 14 common frames omitted 
 
Caused by: java.lang.IllegalArgumentException: A ServletContext is required to configure default servlet handling 
 
\t at org.springframework.util.Assert.notNull(Assert.java:112) 
 
\t at org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer.<init>(DefaultServletHandlerConfigurer.java:53) 
 
\t at org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.defaultServletHandlerMapping(WebMvcConfigurationSupport.java:426) 
 
\t at org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$EnableWebMvcConfiguration$$EnhancerBySpringCGLIB$$f9a7b9e6.CGLIB$defaultServletHandlerMapping$34(<generated>) 
 
\t at org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$EnableWebMvcConfiguration$$EnhancerBySpringCGLIB$$f9a7b9e6$$FastClassBySpringCGLIB$$26f1a4a6.invoke(<generated>) 
 
\t at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) 
 
\t at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:309) 
 
\t at org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$EnableWebMvcConfiguration$$EnhancerBySpringCGLIB$$f9a7b9e6.defaultServletHandlerMapping(<generated>) 
 
\t at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
 
\t at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
 
\t at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
 
\t at java.lang.reflect.Method.invoke(Unknown Source) 
 
\t at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) 
 
\t ... 15 common frames omitted 
 

 
Error creating bean with name 'defaultServletHandlerMapping' 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 'defaultServletHandlerMapping' threw exception; nested exception is java.lang.IllegalArgumentException: A ServletContext is required to configure default servlet handling

Мой Главный класс:

package com.pb.relay; 
 

 
import org.springframework.boot.SpringApplication; 
 
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 
 
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; 
 
import org.springframework.context.annotation.ComponentScan; 
 
import org.springframework.context.annotation.Configuration; 
 
import org.springframework.retry.annotation.EnableRetry; 
 
import org.springframework.scheduling.annotation.EnableAsync; 
 
import org.springframework.scheduling.annotation.EnableScheduling; 
 
import org.springframework.web.servlet.config.annotation.EnableWebMvc; 
 

 
@Configuration 
 
@ComponentScan 
 
@EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class }) 
 
@EnableAsync 
 
@EnableRetry 
 
@EnableScheduling 
 
public class RelayDesktopApp { 
 

 
    public static void main(String[] args) { 
 
     try { 
 
      SpringApplication app = new SpringApplication(RelayDesktopApp.class); 
 
      app.setHeadless(false); 
 
      app.run(args); 
 
     } catch (Throwable t) { 
 
      System.err.println(t.getMessage()); 
 
     } 
 
    } 
 
}

Не уверен, что причина этой ошибки: Ошибка при создании фасоль с name 'defaultServletHandlerMapping'. У меня нет НИКАКОГО, если любые @EnableWebMvc аннотации.

Любая обратная связь?

ответ

6

@EnableAutoConfiguration также делает авто конфиги для WebMvc, поэтому пожалуйста исключить это, а также: -

@EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class,WebMvcAutoConfiguration.class }) 
5

SpringApplication По умолчанию, выведут ли или нет, вы создаете веб-приложение на основе того, что на пути к классам , Если у вас есть веб-связанные зависимости на пути к классам, но не строить веб-приложение, вы можете явно указать SpringApplication, что вы не хотите, веб-приложения:

app.setWebEnvironment(false); 

Это предпочтительнее явно отключить веб поскольку это означает, что вам не нужно знать, что такое те классы автоконфигурации, и позволяет Spring Boot позаботиться об этом для вас.

Смежные вопросы