Spring整合Struts2
1.导入整合包
SSH总包:
2.在Action设置Service属性
//Customer业务层CustomerService private CustomerServiceImpl customerService; public void setCustomerService(CustomerServiceImpl customerService) { this.customerService = customerService; }
3.将Action通过Spring管理
applicationContext.xml
<!-- 客户的控制层 --> <!-- action是多例的 加scope属性 --> <bean id="customerAction" class="com.ssh.web.action.CustomerAction" scope="prototype"> <property name="customerService" ref="customerService"/> </bean>
4.设置actionBean的scope属性并且注入
5.struts.xml中的修改,把全路径修改成ID值
<action name="customer_*" class="customerAction" method="{1}"> </action>
6.测试
public String add(){ System.out.println("控制层:增加客户..."); //调用业务层 customerService.save(customer); return NONE; }