用spring2写的service怎么注入到struts2的action中去
1个回答
展开全部
在action中私有化service属性,并生成set方法。同时在配置文件中将service的bean注入到action的bean中
例如:配置文件中:
<bean id="orderAction" class="cn.itcast.shop.order.OrderAction" scope="prototype">
<property name="orderService" ref="orderService"></property>
</bean>
<bean id="orderService" class="cn.itcast.shop.order.OrderService">
<property name="orderDao" ref="orderDao"></property>
</bean>
action中:
public class OrderAction extends ActionSupport{
// 注入OrderService
private OrderService orderService;
public void setOrderService(OrderService orderService) {
this.orderService = orderService;
}
例如:配置文件中:
<bean id="orderAction" class="cn.itcast.shop.order.OrderAction" scope="prototype">
<property name="orderService" ref="orderService"></property>
</bean>
<bean id="orderService" class="cn.itcast.shop.order.OrderService">
<property name="orderDao" ref="orderDao"></property>
</bean>
action中:
public class OrderAction extends ActionSupport{
// 注入OrderService
private OrderService orderService;
public void setOrderService(OrderService orderService) {
this.orderService = orderService;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询