首页 > 解决方案 > java.lang.IllegalStateException: : 无法初始化上下文,因为已经存在根应用程序上下文

问题描述

我正在尝试将部署在 weblogic 12 上的应用程序迁移到 tomcat 9,这样做时我面临以下异常

java.lang.IllegalStateException:无法初始化上下文,因为已经存在根应用程序上下文 - 检查您的 web.xml 中是否有多个 ContextLoader* 定义!

我的 web.xml 的内容如下

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_4.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
                             http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
    id="WebApp_ID" version="2.4">

    <display-name>Temp</display-name>
    <description>Temp Webservice</description>

    <context-param>
        <param-name>applicationName</param-name>
        <param-value>Temp</param-value>
    </context-param>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring-ws-servlet.xml,/WEB-INF/spring-jpa.xml,/WEB-INF/spring-strategy.xml,/WEB-INF/spring-sdk.xml</param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <listener>
        <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
    </listener>

     <resource-ref>
        <description>Oracle Datasource</description>
        <res-ref-name>jdbc/TEMP_DS_RW</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>

    <servlet>
        <servlet-name>spring-ws</servlet-name>
        <servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>
        <load-on-startup>2</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>spring-ws</servlet-name>
        <url-pattern>/services/temp</url-pattern>
    </servlet-mapping>


</web-app>

我的 Weblogic.xml 的内容如下

<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.7/weblogic-web-app.xsd">
    <wls:weblogic-version>12.1.3</wls:weblogic-version>
    <wls:context-root>temp-service-v2</wls:context-root>
    <wls:container-descriptor>
        <wls:prefer-application-packages>
            <wls:package-name>org.slf4j</wls:package-name>
        </wls:prefer-application-packages>
        <!-- if not using prefer-application-resources you will get a warning like this: -->
        <!-- Class path contains multiple SLF4J bindings -->
        <!-- SLF4J: Found binding in [jar:file:/C:/wls1211/modules/org.slf4j.jdk14_1.6.1.0.jar!/org/slf4j/impl/StaticLoggerBinder.class] -->
        <wls:prefer-application-resources>
            <wls:resource-name>org/slf4j/impl/StaticLoggerBinder.class</wls:resource-name>
        </wls:prefer-application-resources>
        <wls:show-archived-real-path-enabled>true</wls:show-archived-real-path-enabled>
    </wls:container-descriptor>
</wls:weblogic-web-app>

注意:Tomcat 将无法理解 weblogic.xml,因此我在我的应用程序的 META-INF 文件夹中创建了 context.xml 文件,并且 context.xml 的内容如下

<Context path="/temp-service-v2"/>

我的战争文件的名称是 temp-service-v2.war

标签: javatomcatservletsmigrationweblogic

解决方案


推荐阅读