配置spring+struts1+ibtais时,向action中注入的service一直为null,怎么处理,求大神帮忙处理一下
我的spring配置文件<beanid="userAction"class="com.shunde.action.UserAction"scope="singleton"...
我的spring配置文件
<bean id="userAction" class="com.shunde.action.UserAction" scope="singleton">
<property name="userService" ref="userSI"/>
</bean>
<bean id="userSI" class="com.shunde.service.impl.UserServiceImpl">
<property name="userDao" ref="userDao" />
</bean>
<bean id="userService" parent="abstractTxDefinition">
<property name="target" ref="userSI" />
</bean>
<bean id="userDao" class="com.shunde.dao.impl.UserDaoImpl">
<property name="sqlMapClient" ref="sqlMapClient" />
</bean>
我的struts-config配置文件
<struts-config>
<form-beans>
<form-bean name="userManagerForm" type="com.shunde.form.UserForm" />
</form-beans>
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="classpath:applicationContext.xml" />
</plug-in>
<action-mappings>
<!-- 用户管理Action -->
<action path="/userAction" name="userManagerForm" scope="request"
type="com.shunde.action.UserAction">
</action>
</action-mappings>
<controller>
<set-property property="processorClass"
value="org.springframework.web.struts.DelegatingRequestProcessor" />
</controller>
<message-resources parameter="ApplicationResources" />
</struts-config>
我的action
public class UserAction extends BaseAction {
private UserService userService;
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
try {
System.out.println(user.getUsername());
System.out.println(userService);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public UserService getUserService() {
return userService;
}
public void setUserService(UserService userService) {
System.out.println("aaaaaa");
this.userService = userService;
}
} 展开
<bean id="userAction" class="com.shunde.action.UserAction" scope="singleton">
<property name="userService" ref="userSI"/>
</bean>
<bean id="userSI" class="com.shunde.service.impl.UserServiceImpl">
<property name="userDao" ref="userDao" />
</bean>
<bean id="userService" parent="abstractTxDefinition">
<property name="target" ref="userSI" />
</bean>
<bean id="userDao" class="com.shunde.dao.impl.UserDaoImpl">
<property name="sqlMapClient" ref="sqlMapClient" />
</bean>
我的struts-config配置文件
<struts-config>
<form-beans>
<form-bean name="userManagerForm" type="com.shunde.form.UserForm" />
</form-beans>
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="classpath:applicationContext.xml" />
</plug-in>
<action-mappings>
<!-- 用户管理Action -->
<action path="/userAction" name="userManagerForm" scope="request"
type="com.shunde.action.UserAction">
</action>
</action-mappings>
<controller>
<set-property property="processorClass"
value="org.springframework.web.struts.DelegatingRequestProcessor" />
</controller>
<message-resources parameter="ApplicationResources" />
</struts-config>
我的action
public class UserAction extends BaseAction {
private UserService userService;
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
try {
System.out.println(user.getUsername());
System.out.println(userService);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public UserService getUserService() {
return userService;
}
public void setUserService(UserService userService) {
System.out.println("aaaaaa");
this.userService = userService;
}
} 展开
1个回答
展开全部
也是刚学,说的有不对的地方还请见谅呀\r\nstruts2就是通过前台页面(JSP)发出一个action的请求,在struts.xml中配置中寻找对应的action应该由哪个类来处理,它就会new 一个对应的action的实例,当然 在new action实例时要用到其它类,比如一个登录请求(loginAction)它要调用一个service(例如:loginService),这里我们就可以\r\n回答到这,才发现,您说的不是 spring而是springside,不会,没听说过,
追问
我这个是struts1,不是struts2
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询