【问题标题】:Setting the correct classloader into the spring context within a tomcat container将正确的类加载器设置到 tomcat 容器中的 spring 上下文中
【发布时间】:2023-03-29 19:25:01
【问题描述】:

我们在 apache tomcat 7 容器中运行一个 servlet。该应用程序使用 apache camel 和 spring。当应用程序启动时,我们会在启动过程中记录此警告:

Cannot find the class loader from application context, using the thread context class loader instead

我如何告诉 spring/camel 使用哪个类加载器来消除此警告?

【问题讨论】:

    标签: java spring tomcat apache-camel


    【解决方案1】:

    您可以在定义 servlet 本身的 WebServletContext 时加载上下文

     <servlet>
        <servlet-name>admin</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
          <param-name>contextConfigLocation</param-name>
          <param-value>
                    /WEB-INF/spring/*.xml
                </param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
      </servlet>
      <servlet-mapping>
        <servlet-name>admin</servlet-name>
        <url-pattern>/</url-pattern>
      </servlet-mapping>
    

    【讨论】:

    • 感谢您的提示。我们使用基于 java 的 servlet 3.0 配置,所以我解决了警告:rootContext = new AnnotationConfigWebApplicationContext(); rootContext.setClassLoader(Thread.currentThread().getContextClassLoader());
    猜你喜欢
    • 2014-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-31
    相关资源
    最近更新 更多