Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » Struts 2 »

Re: Struts2 and spring2 fails, adding RequestContextFilter/Listener doesnt work.

Peder Larsen

2006-12-23

Replies:

Hm, then all i can think of is that i have some incompatible JARs in my pom,
here is my pom.xml,

<?xml version="1.0" encoding="UTF-8"?><project>
<modelVersion>4.0.0</modelVersion>
<groupId>pedro</groupId>
<artifactId>research2</artifactId>
<packaging>war</packaging>
<name>Struts 2 Starter</name>
<version>1.0-SNAPSHOT</version>
<description>Struts 2 Starter</description>
<url>http://www.myComp.com</url>
<build>
  <outputDirectory>src/main/webapp/WEB-INF/classes</outputDirectory>
  <finalName>research2</finalName>
  <plugins>
   <plugin>
    <groupId>org.mortbay.jetty</groupId>
    <artifactId>maven-jetty-plugin</artifactId>
    <dependencies>
      <dependency>
       <groupId>org.apache.geronimo.specs</groupId>
       <artifactId>geronimo-j2ee_1.4_spec</artifactId>
       <version>1.0</version>
       <scope>provided</scope>
      </dependency>
    </dependencies>
    <configuration>
      <contextPath>/</contextPath>
      <scanIntervalSeconds>10</scanIntervalSeconds>
    </configuration>
   </plugin>
  </plugins>
</build>

<repositories>
  <repository>
   <releases>
    <enabled>false</enabled>
   </releases>
   <snapshots>
    <updatePolicy>always</updatePolicy>
    <checksumPolicy>ignore</checksumPolicy>
   </snapshots>
   <id>snapshots-maven-codehaus</id>
   <name>snapshots-maven-codehaus</name>
   <url>http://snapshots.maven.codehaus.org/maven2</url>
  </repository>
  <repository>
   <releases>
    <enabled>false</enabled>
   </releases>
   <snapshots>
    <updatePolicy>always</updatePolicy>
    <checksumPolicy>ignore</checksumPolicy>
   </snapshots>
   <id>apache</id>
   <name>apache</name>
   <url>http://cvs.apache.org/repository</url>
   <layout>legacy</layout>
  </repository>
  <repository>
   <releases />
   <snapshots />
   <id>apache.snapshots</id>
   <name>Apache Maven Repository (Snapshots and Test Builds)</name>
   <url>http://cvs.apache.org/maven-snapshot-repository</url>
  </repository>
  <repository>
   <releases>
    <enabled>false</enabled>
   </releases>
   <snapshots>
    <updatePolicy>always</updatePolicy>
    <checksumPolicy>ignore</checksumPolicy>
   </snapshots>
   <id>opensymphony</id>
   <name>opensymphony</name>
   <url>http://maven.opensymphony.com</url>
   <layout>legacy</layout>
  </repository>
</repositories>
<!-- DEPENDENCIES, MAYBE I HAVE SOME INCOMPATIBLE JARs HERE?! -->
<dependencies>
  <dependency>
   <groupId>junit</groupId>
   <artifactId>junit</artifactId>
   <version>3.8.1</version>
   <scope>test</scope>
  </dependency>
  <dependency>
   <groupId>org.apache.struts</groupId>
   <artifactId>struts2-core</artifactId>
   <version>2.0.2-SNAPSHOT</version>
  </dependency>
  <dependency>
   <groupId>org.apache.struts</groupId>
   <artifactId>struts2-sitemesh-plugin</artifactId>
   <version>2.0.2-SNAPSHOT</version>
  </dependency>
  <dependency>
   <groupId>org.apache.struts</groupId>
   <artifactId>struts2-spring-plugin</artifactId>
   <version>2.0.2-SNAPSHOT</version>
   <exclusions>
    <exclusion>
      <artifactId></artifactId>
      <groupId>org.springframework</groupId>
    </exclusion>
    <exclusion>
      <artifactId>spring-beans</artifactId>
      <groupId>org.springframework</groupId>
    </exclusion>
    <exclusion>
      <artifactId>spring-context</artifactId>
      <groupId>org.springframework</groupId>
    </exclusion>
    <exclusion>
      <artifactId>spring-web</artifactId>
      <groupId>org.springframework</groupId>
    </exclusion>
   </exclusions>
  </dependency>

  <dependency>
   <groupId>freemarker</groupId>
   <artifactId>freemarker</artifactId>
   <version>2.3.4</version>
  </dependency>
  <dependency>
   <groupId>javax.servlet</groupId>
   <artifactId>servlet-api</artifactId>
   <version>2.4</version>
   <scope>provided</scope>
  </dependency>
  <dependency>
   <groupId>javax.servlet</groupId>
   <artifactId>jsp-api</artifactId>
   <version>2.0</version>
   <scope>provided</scope>
  </dependency>
  <dependency>
   <groupId>commons-logging</groupId>
   <artifactId>commons-logging</artifactId>
   <version>1.0.4</version>
  </dependency>
  <dependency>
   <groupId>commons-fileupload</groupId>
   <artifactId>commons-fileupload</artifactId>
   <version>1.1.1</version>
  </dependency>
  <dependency>
   <groupId>uk.ltd.getahead</groupId>
   <artifactId>dwr</artifactId>
   <version>1.1-beta-3</version>
  </dependency>
  <dependency>
   <groupId>opensymphony</groupId>
   <artifactId>sitemesh</artifactId>
   <version>2.2.1</version>
  </dependency>
  <dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-beans</artifactId>
   <version>2.0.1</version>
  </dependency>
  <dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-core</artifactId>
   <version>2.0.1</version>
  </dependency>
  <dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-context</artifactId>
   <version>2.0.1</version>
  </dependency>
  <dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-web</artifactId>
   <version>2.0.1</version>
  </dependency>
  <dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-core</artifactId>
   <version>2.0.1</version>
  </dependency>
</dependencies>
</project>


Maybe you can have a quick look, the JAR that i suspect might be some hazzle
with is:
   <groupId>org.apache.struts</groupId>
   <artifactId>struts2-spring-plugin</artifactId>
   <version>2.0.2-SNAPSHOT</version>

for which i have defined some exclusions for to avoid fetching 1.2.x JARs.

I also pass in my actual eclipse classpath so you can see what maven2
actually resolves,
path="M2_REPO/org/springframework/spring-context/2.0.1/spring-
context-2.0.1.jar"/>
path="M2_REPO/aopalliance/aopalliance/1.0/aopalliance-1.0.jar" />
path="M2_REPO/org/springframework/spring-core/2.0.1/spring-core-2.0.1.jar"/>
path="M2_REPO/uk/ltd/getahead/dwr/1.1-beta-3/dwr-1.1-beta-3.jar"/>
path="M2_REPO/commons-fileupload/commons-fileupload/1.1.1/commons-
fileupload-1.1.1.jar"/>
path="M2_REPO/org/springframework/spring-beans/2.0.1/spring-beans-2.0.1.jar
"/>
path="M2_REPO/opensymphony/xwork/2.0-RC1-SNAPSHOT/xwork-2.0-RC1-SNAPSHOT.jar
"/>
path="M2_REPO/org/apache/struts/struts2-spring-plugin/2.0.2-SNAPSHOT/struts2-
spring-plugin-2.0.2-SNAPSHOT.jar"/>
path="M2_REPO/org/apache/struts/struts2-sitemesh-plugin/2.0.2-SNAPSHOT/struts2-
sitemesh-plugin-2.0.2-SNAPSHOT.jar"/>
path="M2_REPO/freemarker/freemarker/2.3.4/freemarker-2.3.4.jar"/>
path="M2_REPO/org/springframework/spring-web/2.0.1/spring-web-2.0.1.jar"/>
path="M2_REPO/javax/servlet/servlet-api/2.4/servlet-api-2.4.jar" />
path="M2_REPO/org/apache/struts/struts2-core/2.0.2-SNAPSHOT/struts2-
core-2.0.2-SNAPSHOT.jar"/>
path="M2_REPO/opensymphony/sitemesh/2.2.1/sitemesh-2.2.1.jar" />
path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar"
sourcepath="M2_REPO/junit/junit/3.8.1/junit-3.8.1-sources.jar"/>
path="M2_REPO/javax/servlet/jsp-api/2.0/jsp-api-2.0.jar"/>
path="M2_REPO/commons-logging/commons-logging/1.0.4/commons-
logging-1.0.4.jar" />
path="M2_REPO/commons-io/commons-io/1.1/commons-io-1.1.jar" />
path="M2_REPO/ognl/ognl/2.6.9/ognl-2.6.9.jar"/>
path="M2_REPO/org/apache/struts/struts2-api/2.0.2-SNAPSHOT/struts2-
api-2.0.2-SNAPSHOT.jar"/>


Thanks for all help so far folks, sorry for the inconvenience.
Maybe i should add im using jetty6 with maven, started with mvn jetty:run

Regards Peder!

On 12/23/06, Nuwan Chandrasoma <mymailnot@(protected):
>
> Hi Peder,
>
> This looks ok for me, try by adding "struts.objectFactory = spring" into
> struts.properties file and see
>
> Thanks,
>
> Nuwan.
>
> ----- Original Message -----
> From: "Peder Larsen" <larsen.peder@(protected)>
> To: "Struts Users Mailing List" <user@(protected)>
> Sent: Saturday, December 23, 2006 3:31 AM
> Subject: Re: Struts2 and spring2 fails, adding
> RequestContextFilter/Listener
> doesnt work.
>
>
> > Ok my config is:
> > applicationContext.xml,
> > <?xml version="1.0" encoding="UTF-8"?>
> > <beans xmlns="http://www.springframework.org/schema/beans"
> >     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> >     xmlns:aop="http://www.springframework.org/schema/aop"
> >     xsi:schemaLocation="http://www.springframework.org/schema/beans
> > http://www.springframework.org/schema/beans/spring-beans.xsd
> >     http://www.springframework.org/schema/aop
> > http://www.springframework.org/schema/aop/spring-aop.xsd">
> >
> >   <bean id="userInfo" class="models.UserInfo" autowire="byType"
> > scope="session"></bean>
> >   <bean id="indexAction" class="actions.IndexAction" scope="prototype">
> >     <property name="userInfo" ref="userInfo" />
> >   </bean>
> > </beans>
> > struts.xml,
> > <?xml version="1.0" encoding="UTF-8"?>
> > <!DOCTYPE struts PUBLIC
> >   "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
> >   "http://struts.apache.org/dtds/struts-2.0.dtd">
> > <struts>
> >   <constant name="struts.objectFactory" value="spring"></constant>
> >   <package name="unrestrictedActions" extends="struts-default" >
> >     <interceptors>
> >       <interceptor name="login" class="interceptor.LoginInterceptor
> "/>
> >       <interceptor-stack name="secureStack">
> >        <interceptor-ref name="login"/>
> >        <interceptor-ref name="defaultStack"/>
> >       </interceptor-stack>
> >     </interceptors>
> >
> >     <default-interceptor-ref name="secureStack"/>
> >
> >     <action name="index" class="indexAction">
> >        <result type="freemarker">/ftl/index.ftl</result>
> >     </action>
> >   </package>
> > </struts>
> > web.xml,
> > <?xml version="1.0" encoding="UTF-8"?>
> >
> > <web-app id="starter" version="2.4"
> >   xmlns="http://java.sun.com/xml/ns/j2ee"
> >   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> >   xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
> > http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
> >
> > <display-name>Test webapp</display-name>
> >
> >  <context-param>
> >   <param-name>contextConfigLocation</param-name>
> >   <param-value>classpath*:applicationContext*.xml</param-value>
> >  </context-param>
> >
> >   <filter>
> >     <filter-name>action2-cleanup</filter-name>
> >     <filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp
> > </filter-class>
> >   </filter>
> >   <filter>
> >     <filter-name>action2</filter-name>
> >     <filter-class>org.apache.struts2.dispatcher.FilterDispatcher
> > </filter-class>
> >   </filter>
> >   <filter>
> >     <filter-name>requestContextFilter</filter-name>
> >     <filter-class>org.springframework.web.filter.RequestContextFilter
> > </filter-class>
> >   </filter>
> >   <filter-mapping>
> >     <filter-name>requestContextFilter</filter-name>
> >     <url-pattern>/*</url-pattern>
> >   </filter-mapping>
> >   <filter-mapping>
> >     <filter-name>action2-cleanup</filter-name>
> >     <url-pattern>/*</url-pattern>
> >   </filter-mapping>
> >   <filter-mapping>
> >     <filter-name>action2</filter-name>
> >     <url-pattern>/*</url-pattern>
> >   </filter-mapping>
> >
> >   <listener>
> >     <listener-class>
> > org.springframework.web.context.ContextLoaderListener</listener-class>
> >   </listener>
> >   <welcome-file-list>
> >     <welcome-file>index.jsp</welcome-file>
> >   </welcome-file-list>
> > </web-app>
> >
> > Whew! That is a long listing, i've also tried with the
> > org.springframework.web.context.request.RequestContextListener listener
> > but
> > run in the same problem.
> >
> > Also tried what nuwan chandrasoma suggested in the thread above this but
> > i've already tried that.
> >
> > So anyone spots whats missing?
> >
> > Thanks for all help.
> > On 12/23/06, Wendy Smoak <wsmoak@(protected):
> >>
> >> On 12/22/06, Peder Larsen <larsen.peder@(protected):
> >>
> >> > I've been trying for some time now to get my basic struts2 test up
> and
> >> > running. The problem i have is that i need to inject one UserInfo pr
> >> session
> >> > into my FooAction. I want to use spring2 for this since it has better
> >> > "scope" support than spring1.
> >>
> >> Are you using the 2.0.1 beta release?
> >>
> >> > Anyone know what i might do to fix it?
> >>
> >> Post the relevant parts of your configuration files and code, and see
> >> if someone can spot the problem.
> >>
> >> --
> >> Wendy
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@(protected)
> >> For additional commands, e-mail: user-help@(protected)
> >>
> >>
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@(protected)
> For additional commands, e-mail: user-help@(protected)
>
>
©2008 junlu.com - Jax Systems, LLC, U.S.A.