Hi Dave
Hi all

Finally i got it working the "spring"-way, meaning, when also delegating the
instantiation of action classes to spring. The "default" way, meaning
letting struts2 creating the action instances still doesn't work and i
really don't understand why.

Thanks to everyone that help me getting it working!

For anybody having similar problems and reading this post some day in the
future in the archive:

- include spring.jar. Struts2-core.jar, struts2-spring-plugin.jar,
xwork.jar, ognl.jar, freemarker.jar and commons-logging.jar to your
/WEB-INF/lib dir.

- put web.xml under /WEB-INF.

- put applicationContex.xml somewehere to your classpath. Same for
struts.xml and if you need struts.properties (which is not needed as long as
you set the required params in the struts.xml. This mainly refers to the
setting of the object factory).

- You can use the default.properties from struts2-core.jar as template for
your own struts.properties (can by found unter org/apache/struts2/). Set
struts.objectFactory = spring and struts.objectFactory.spring.autoWire =
name.

- Your basic web.xml would look like:
----------------------------------------------------------------------------
-<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee";
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";>  
    <filter>  
        <filter-name>struts2</filter-name>  
 
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>

    </filter>  
    <filter-mapping>  
        <filter-name>struts2</filter-name>  
        <url-pattern>/*</url-pattern>  
    </filter-mapping>  
    <listener>
 
<listener-class>org.springframework.web.context.ContextLoaderListener</liste
ner-class>
    </listener>    
    
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
    
    <context-param>
        <param-name>contextConfigLocation</param-name>
        
        <param-value>classpath*:applicationContext*.xml</param-value>
    </context-param>
    
    
</web-app>
----------------------------------------------------------------------------
-

- Your applicationContext.xml could look like this. Note that you first have
to define the business logic beans you later on need upon definition of the
action class beans. Also make sure you understand, that in struts.xml you
will have to define the action classes using their spring bean id and not
there class names! In this case the injection works by defining a
constructor argument. This could also be done using a setter method (than
you would pass a property argument).
----------------------------------------------------------------------------
-
<?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";
    xmlns:tx="http://www.springframework.org/schema/tx";
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
    http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
    http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd";>

    <bean id="businessService"
class="com.example.businesslogic.BusinessService" />
    
    <bean id="someAction" scope="prototype" class="com.example.SomeAction">
        <constructor-arg ref="businessService" />
    </bean>
    
</beans>
----------------------------------------------------------------------------
-

- Your struts.properties would look like:
----------------------------------------------------------------------------
-
<?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 name="struts.devMode" value="true" />

    <package name="somePackageName" extends="struts-default">

        <action name="login" method="login" class="someAction">
            <result name="input">/login.jsp</result>
            <result name="success">/mainapplication.jsp</result>
        </action>
        
        <action name="logout" method="logout" class="someAction">
            <result name="success">/login.jsp</result>
        </action>
        
    </package>
    
</struts>
----------------------------------------------------------------------------
-

I hope there's nothing wrong i wrote. Ohterwise plz feel free to
correct/comment. 

Frank






---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to