Spring-boot无法以ApplicationContextException启动

时间:2018-09-16 07:51:05

标签: spring spring-boot

@SpringBootApplication
@Import({WebConfigurer.class})
@ComponentScan("com.jde.nlu.qe")
@PropertySource({"classpath:boot.properties", "classpath:important.properties", "classpath:jss.properties",
        "classpath:system.properties", "classpath:ump.properties"})
@EnableAutoConfiguration
public class JnluQEWebStart extends SpringBootServletInitializer {

    public static void main(String[] args) {

        SpringApplication.run(JnluQEWebStart.class, args);
    }
}

我的WebConfigurer类:

@Configuration
@ImportResource({ "classpath:spring/spring-base.xml"})
public class WebConfigurer implements WebMvcConfigurer {
    /**
     * 设置字符编码<br/>
     *
     * @return Filter
     */
    @Bean
    public Filter characterEncodingFilter() {
        CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
        characterEncodingFilter.setEncoding("UTF-8");
        characterEncodingFilter.setForceEncoding(true);
        return characterEncodingFilter;
    }

    /**
     * 增加对put方法的支持<br/>
     *
     * @return FilterRegistrationBean
     */
    @Bean
    public FilterRegistrationBean httpPutFormContentFilter() {
        FilterRegistrationBean filterRegBean = new FilterRegistrationBean();
        HttpPutFormContentFilter httpPutFormContentFilter = new HttpPutFormContentFilter();
        filterRegBean.setFilter(httpPutFormContentFilter);
        List<String> urlPatterns = new ArrayList<String>();
        urlPatterns.add("/*");
        filterRegBean.setUrlPatterns(urlPatterns);
        return filterRegBean;
    }

    /**
     * 将/WEB-INF/resources/设置为资源目录
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**").addResourceLocations("/WEB-INF/resources/").setCachePeriod(0);
    }

    /**
     * 增加ETAG标签的过滤器<br/>
     *
     * @return FilterRegistrationBean
     */
    @Bean
    public FilterRegistrationBean addEtagFilter() {
        FilterRegistrationBean filterRegBean = new FilterRegistrationBean();
        ShallowEtagHeaderFilter etagFilter = new ShallowEtagHeaderFilter();
        filterRegBean.setFilter(etagFilter);
        List<String> urlPatterns = new ArrayList<String>();
        urlPatterns.add("/api/*");
        filterRegBean.setUrlPatterns(urlPatterns);
        return filterRegBean;
    }

    @Bean(name = "multipartResolver")
    public CommonsMultipartResolver multipartResolver() {
        CommonsMultipartResolver commonsMultipartResolver = new CommonsMultipartResolver();
        return commonsMultipartResolver;
    }
}

当我运行“ JnluQEWebStart”时,收到以下错误消息:

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-09-16 at 00:44:28.164 [main] ERROR org.springframework.boot.SpringApplication [863] [reportFailure] - Application run failed org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:155) ~[spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:544) ~[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:780) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:412) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:333) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1277) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1265) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
    at com.jde.nlu.qe.boot.JnluQEWebStart.main(JnluQEWebStart.java:22) [classes/:?]
Caused by: org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getWebServerFactory(ServletWebServerApplicationContext.java:204) ~[spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:178) ~[spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:152) ~[spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
    ... 8 more

我已经搜索了很长时间,但是找不到有效的解决方案。

0 个答案:

没有答案