Spring2.08 webwork2.24
There is a problem with the service injected into the Action. The injected service is not the same object as the referenced service.
Whether it is a singleton or not, the service referenced in the execute method is null, and the service in the setter method is valid when the initialization is declared as singleton="true".
Or declaring the service as static is no problem.
Action
Java code Collection code
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.. Omit
the injected
Java code of Action
<?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-app version="2.4" <?xml version="1.0" encoding="UTF-8"?> Java code Collection code
web.xml
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>
Similar problems were also found in javae ,but. . Still not solved
http://www.iteye.com/post/139291
solved it.
The original default is to declare the service that injects action according to the name
in webwork.properties
, and that's it. . . vomiting blood. . .
webwork.objectFactory.spring.autoWire = type
Programmer's action
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=326323419&siteId=291194637
Ranking