java.lang.IllegalStateException: :Cannot initialize context because there is already a root application context present

我的梦境 提交于 2021-01-29 13:08:39

问题


I am trying to migrate application deployed on weblogic 12 to tomcat 9 and while doing so I am facing following exception

java.lang.IllegalStateException: Cannot initialize context because there is already a root application context present - check whether you have multiple ContextLoader* definitions in your web.xml!

content of my web.xml is as follows

<?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>

Content of my Weblogic.xml is as follows

<?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>

Note : Tomcat would not be able to understand weblogic.xml hence I have created context.xml file in META-INF folder of my application and content of context.xml is as follows

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

Name of my war file is temp-service-v2.war

来源:https://stackoverflow.com/questions/57591173/java-lang-illegalstateexception-cannot-initialize-context-because-there-is-alr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!