Struts2+Spring Integration

1k Views Asked by At

Trying to integrate Struts2 and Spring in my application using Maven. I have placed all the dependencies in Pom file which is related to Spring-web,Spring,Struts2-spring plugin

<!-- Spring framework --> 
     <dependency>
 <groupId>org.springframework</groupId>
 <artifactId>spring</artifactId>
 <type>jar</type>
 <version>2.5.6</version>
 </dependency>
 <dependency>
 <groupId>org.springframework</groupId>
 <artifactId>spring-web</artifactId>
 <version>2.5.6</version>
 </dependency>
 <dependency>
 <groupId>org.apache.struts</groupId>
 <artifactId>struts2-spring-plugin</artifactId>
 <version>2.2.3</version>
 </dependency>

and i have included the following in Web.xml file,

<filter>
    <filter-name>struts2</filter-name>
    <filter-class>
        org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
    </filter-class>
    </filter>
    <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping> 
    <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
      </listener>  

     <context-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param> 

When i running using Maven war file is generated and when i deploying my war file in my server(glassfish) error message is showing like

"Error An error has occurred
Error occurred during deployment: Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: java.lang.NoClassDefFoundError: Could not initialize class org.springframework.web.context.ContextLoader. Please see server.log for more details."

So anyone please help me to fix this issue.

1

There are 1 best solutions below

6
On

ContextLoader is in the Spring-web jar . The error is because this class definition could not be found . Check if this dependency is present in your .m2 folder .

If it is not downloaded automatically for some reason manually install it using the mvn install:install command . See Jars Issues in Maven Spring Hibernate Project for more probable solutions .

Try

  1. Doing a mvn package and see if the Spring jar is in your war

  2. After doing mvn eclipse:eclipse , refresh the eclipse ,clean your eclipse workspace - project- clean (Tick Build automatically)

open up the .classpath file and check for an entry similar to

or right click the project -->properties-->java build path-->libraries and see if the spring-web jar is there .

  1. Open up the .m2 repo and see if the jar is inside the repo - If not do a install:install

  2. do an mvn dependency:tree and see if the jar comes up .

That's pretty much what I can suggest