service注入action两种方式

1、采用自动装配方式,即不在spring中注入action(系统默认的);

好处在于:不必在struts.xml中写了配置文件后,又在spring的配置文件中再写一遍配置

如:

在struts.xml中写

<action name="loginAction" class="com.lk.loginAction" />

就可以了。

2、在spring中注入action

缺点在于:

在struts.xml中写

<action name="loginAction" class="loginAction" />

同时在spring配置文件中需要写

<bean id="loginAction" class="com.lk.loginAction" >

     <property ref="service" />

</bean>

这样看来配置文件要比第一种要繁琐一些。

但是据称这种方式。适合配置AOP的内容。而且struts2官方文档上也是采用的这种配置

猜你喜欢

转载自441907488-qq-com.iteye.com/blog/2335027