zoukankan      html  css  js  c++  java
  • java.lang.IllegalStateException: Cannot initialize context because there is already a root application context present

    @Controller
    @ComponentScan
    @Configuration
    @EnableScheduling
    @EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class, RedisAutoConfiguration.class, MybatisAutoConfiguration.class})
    @ImportResource(locations = {"classpath*:app.xml"})
    public class AppMain extends SpringBootServletInitializer implements ApplicationContextAware {
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
    // return super.configure(builder);
    return builder.sources(AppMain.class);
    }

    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
    servletContext.setInitParameter("logSystem","log4j,logback");
    servletContext.setInitParameter("loggingLevel", "INFO");
    servletContext.setInitParameter("loggingCharset", "UTF-8");
    servletContext.setInitParameter("contextConfigLocation", "<NONE>");
    super.onStartup(servletContext);
    }
    }



     

    For anyone with a similar problem - turns out that spring-jersey used in the project was setting up its own context. My context and the spring-jersey one were initialized in random order apparently. More info here: 
    https://java.net/jira/browse/JERSEY-2038 
    https://java.net/projects/jersey/lists/users/archive/2014-03/message/124 
    The suggested solution of adding:

    servletContext.setInitParameter("contextConfigLocation", "<NONE>");
    

    In WebAppInitializer implementation didn't work reliably due to initialization order. What solved the problem was adding its xml equivalent: 

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value></param-value>
    </context-param> 
    

    as the firt parameter in web.xml, ensuring that its set before the context is initialized.

  • 相关阅读:
    CSS属性值一览
    CSS属性一览
    CSS选择器一览
    HTML颜色编码
    游戏
    数据库系统概念
    关于总结
    章节测试
    我的博客皮肤
    Emeditor所有快捷键操作
  • 原文地址:https://www.cnblogs.com/exmyth/p/11093458.html
Copyright © 2011-2022 走看看