1

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.

Roman C
  • 49,761
  • 33
  • 66
  • 176
1010Logic
  • 11
  • 2
  • few things, why you need Spring-web?? can you provide complete error log? In end my Question is why to use Spring-web and Struts2 since both are MVC based platform – Umesh Awasthi Jan 04 '12 at 05:53
  • Dear Umesh, I am new to Spring. My web application is working fine in Struts2. I want to use spring for DI in my application. So I am trying to integrating. so now u can able to understand my situation. I just take the code from MKYong website and trying to find the integration. – 1010Logic Jan 04 '12 at 06:22
  • @Umesh , he is using spring-web jar for Struts integration . I think you are refering to spring-webmvc which corresponds to Spring MVC framework .Both are different . – Aravind A Jan 04 '12 at 06:25
  • OK!! Just add spring-web jar in your class-path and i hope this should work as the issue is with spring-jar.Since you are using `2.2.3` just upgrade to spring 3.x version in place of `2.5.6` – Umesh Awasthi Jan 04 '12 at 06:27
  • @AravindA: yes i got that,just read it other way in first go :).y i hate this Spring set-up if i want to use DI why not to use only core.I guess trying to use OSGI they are going back-ward steps. – Umesh Awasthi Jan 04 '12 at 06:29
  • QUmesh I guess he needs more than just DI - spring-web gives access to the WebApplicationContext and enhances support for request handling . I agree with you that Spring is trying to cover too much in one go :) – Aravind A Jan 04 '12 at 06:36
  • Add a spring-context dependency. – Dave Newton Jan 04 '12 at 12:51
  • Also, what's your specific need for spring-web? In general you won't need it except for a few very specific things. – Dave Newton Jan 04 '12 at 13:27

1 Answers1

0

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

Community
  • 1
  • 1
Aravind A
  • 9,507
  • 4
  • 36
  • 45
  • Dear Umesh, I am new to Spring. My web application is working fine in Struts2. I want to use spring for DI in my application. So I am trying to integrating. so now u can able to understand my situation. I just take the code from MKYong website and trying to find the integration. – 1010Logic Jan 04 '12 at 06:21
  • I have tried using external jar file in my project but it is showing the same error while deploying in server. I am in learning state of maven and spring too. – 1010Logic Jan 04 '12 at 06:25
  • Thanks a lot for your suggestion. I Have downloaded Spring-web-2.5.6 jar file, placed in my classpath and restarted workspace still the error is showing like could not initialize the class org.springframework.web.context.ContextLoader. Placed my applicationContext.xml in WEB-INF folder. – 1010Logic Jan 04 '12 at 11:11
  • @1010Logic please click the check mark on your screen next to my answer if you have accepted the answer . Thanks . – Aravind A Jan 04 '12 at 11:31
  • When i deploying my war file in server ,showing the error and couldn't get uploaded in server.Yes, I have specified my applicationContext file in Web.Xml file. org.springframework.web.context.ContextLoaderListener contextConfigLocation /WEB-INF/applicationContext.xml index.jsp – 1010Logic Jan 04 '12 at 11:47
  • @1010Logic See my edits - pretty much sumsup my suggestions :) – Aravind A Jan 04 '12 at 12:04