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.

  • 相关阅读:
    Markdown引用图片,且不使用网上链接的解决方法
    测试
    sudo用户权限添加问题
    windows安装ipython
    ansible基本操作
    mysql用户权限操作
    解决windows7系统的快捷方式无法添加到任务栏
    linux下查看磁盘分区的文件系统格式
    mail客户端POP和IMAP协议
    linux设置history历史记录
  • 原文地址:https://www.cnblogs.com/exmyth/p/11093458.html
Copyright © 2011-2022 走看看