程序员的action

spring2.08 webwork2.24
注入Action中的service出现问题,注入的service,和引用的service不是同一个对象。
无论是不是singleton都出现execute方法里面引用的service为null,声明为singleton="true"时初始化时setter方法里的service有效。
或者把service声明为static的也没问题。

Action

Java代码  收藏代码
public class SystemAction extends ActionSupport implements ModelDriven{ 
    SystemModel sm = new SystemModel(); 
    private SystemService systemService; 
     
    public String execute() throws Exception { 
        System.out.println("in execute systemservice is "+systemService); 
        systemService.TestSystemDAO(); 
        return SUCCESS; 
    } 
 
..setter..省略 


Action的注入
Java代码  收藏代码
<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> 
<beans> 
        <bean id="systemAction" class="net.xx.control.action.SystemAction" singleton="false"> 
        <property name="systemService"> 
            <ref bean="userService"/> 
        </property> 
        </bean> 
</beans> 


xwork.xml

Java代码  收藏代码
<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE xwork PUBLIC "-//OpenSymphony Group//XWork 1.0//EN" "http://www.opensymphony.com/xwork/xwork-1.0.dtd"> 
<xwork> 
    <include file="webwork-default.xml" /> 
    <package name="default" extends="webwork-default"> 
        <interceptors> 
            <interceptor-stack name="modelParamsStack"> 
                <interceptor-ref name="params" /> 
                <interceptor-ref name="model-driven"/> 
            </interceptor-stack> 
        </interceptors> 
    </package> 
<include file="net\xx\control\config\webwork-user.xml"/> 
</xwork> 


webwork-user.xml

Java代码  收藏代码
<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE xwork PUBLIC "-//OpenSymphony Group//XWork 1.0//EN" "http://www.opensymphony.com/xwork/xwork-1.0.dtd"> 
<xwork> 
<package name="login" extends="webwork-default" namespace="/user">   
    <action name="login" class="net.xx.control.action.SystemAction"> 
            <result name="success" type="dispatcher"> 
                <param name="location">/index.jsp</param> 
            </result> 
            <result name="error" type="dispatcher"> 
                <param name="location">/login.jsp</param> 
            </result> 
        <interceptor-ref name="modelParamsStack"/> 
    </action> 
</package>  
</xwork> 


web.xml

Java代码  收藏代码
<?xml version="1.0" encoding="UTF-8"?> 
<web-app 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"> 
    <servlet> 
        <servlet-name>webwork</servlet-name> 
        <servlet-class> 
            com.opensymphony.webwork.dispatcher.ServletDispatcher 
        </servlet-class> 
        <init-param> 
            <param-name>contextConfigLocation</param-name> 
            <param-value>/WEB-INF/applicationContext*.xml</param-value> 
        </init-param> 
    <load-on-startup>1</load-on-startup> 
    </servlet> 
 
    <servlet-mapping> 
        <servlet-name>webwork</servlet-name> 
        <url-pattern>*.action</url-pattern> 
    </servlet-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>  
        <filter>  
        <filter-name>openSessionInViewFilter</filter-name>  
        <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>  
    </filter>  
 
    <filter-mapping>  
        <filter-name>openSessionInViewFilter</filter-name>  
        <url-pattern>/*</url-pattern>  
    </filter-mapping> 
</web-app> 


在javae也搜索到类似的问题,但。。还是没解决
http://www.iteye.com/post/139291

解决了
原来默认的是根据name来注入action的service
在webwork.properties
声明一下,就行了。。。吐血。。。
webwork.objectFactory.spring.autoWire = type

你可能感兴趣的:(Web,朋友圈,开发语言,代码和逻辑)