jeudi 30 avril 2020

Creating ApplicationContext more than one time (In struts + Spring project)

I have a legacy system , which is in struts 1 and spring 3, now I need to upgrade the version of spring 3 to 5. I have done almost all the things and everything is working fine. there is only an issue which I face when i start tomcat server.

Let see with code:- This is the web.xml configuration earlier,

<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>WEB-INF/applicationContext.xml</param-value>
    </context-param>
    <servlet>
        <servlet-name>context</servlet-name>
        <servlet-class>
            org.springframework.web.context.ContextLoaderServlet
        </servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet> 

After upgrading the version:-

<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

  <servlet>
        <servlet-name>servlet</servlet-name>
        <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
        <init-param>
          <param-name>config</param-name>
          <param-value>/WEB-INF/struts-config.xml</param-value>
        </init-param>       
        <init-param>
            <param-name>debug</param-name>
            <param-value>2</param-value>
        </init-param>       
        <init-param>
            <param-name>detail</param-name>
            <param-value>2</param-value>
        </init-param>
        <load-on-startup>2</load-on-startup>
    </servlet>  

    <servlet-mapping>
        <servlet-name>servlet</servlet-name>
        <url-pattern>*.do</url-pattern>
   </servlet-mapping>

Now, when I start my tomcat server, then applicationContext environment gets created two time. one for "org.apache.struts.action.ActionServlet" and second for this "org.springframework.web.context.ContextLoaderListener"

check log:

INFO: TLD skipped. URI: http://struts.apache.org/tags-nested is already defined
May 01, 2020 11:14:09 AM org.apache.catalina.startup.TldConfig execute
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
May 01, 2020 11:14:09 AM org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
May 01, 2020 11:14:09 AM org.apache.catalina.core.ApplicationContext log

// First time
INFO: Initializing Spring root WebApplicationContext  


log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
log4j:WARN Please initialize the log4j system properly.
Calling the CacheManager Constructor...
May 01, 2020 11:14:17 AM org.apache.catalina.core.ApplicationContext log
// Second time
INFO: Initializing WebApplicationContext for Struts ActionServlet 'servlet', module ''  

May 01, 2020 11:14:19 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-9090"]
May 01, 2020 11:14:19 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-9009"]
May 01, 2020 11:14:19 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 18889 ms

Suggest me how to fix this.




Aucun commentaire:

Enregistrer un commentaire