【发布时间】:2015-09-29 06:06:48
【问题描述】:
无法让我的 Spring Boot 应用程序在 AWS 实例上运行。它在我的机器上运行良好,但看起来自动装配在一个环境中正确解析,但在另一个环境中却没有。看起来我需要稍微清理一下配置类。任何想法在这里?非常感谢。
**Main class:**
@Configuration
@EnableAutoConfiguration
@EnableConfigurationProperties
@ComponentScan
public class Data {
public static void main(String[] args) throws Exception {
SpringApplication.run(Data.class, args);
}
}
配置:
@EnableWebMvc
@Configuration
public class AquilaDataWebConfig extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/charts/**").addResourceLocations(
"file:///var/lib/aquila/");
registry.addResourceHandler("/**").addResourceLocations(
"classpath:/static/");
}
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("forward:/index.html");
}
@Bean
public InternalResourceViewResolver defaultViewResolver() {
// Need this so we can forward to index.html.
return new InternalResourceViewResolver();
}
}
例外:
Error starting ApplicationContext. To display the auto-configuration report enabled debug logging (start with --debug)
2015-07-09 19:30:55.773 ERROR 18723 [main] --- o.s.boot.SpringApplication : Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultServletHandlerMapping' defined in class path resource [org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.class]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.web.servlet.HandlerMapping org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.defaultServletHandlerMapping()] threw exception; nested exception is java.lang.IllegalArgumentException: A ServletContext is required to configure default servlet handling
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:601)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1113)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1008)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:505)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
at
【问题讨论】:
-
你是部署为jar吗,需要是war部署到托管tomcat实例stackoverflow.com/questions/22646190/…
-
这不起作用,因为我们使用的是基于 jar 的内部 tomcat 容器。谢谢。
标签: java spring spring-mvc tomcat spring-boot