struts2+spring 自动装配的一点疑问

struts2整合spring有两种方式

1、采用自动装配方式,即不在spring中注入action;

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

如:

在struts.xml中写

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

 就可以了。

可以写一个BaseAction 里面放入所有的service接口,其他Action继承它就可以根据自动装备的方式

自动注入自己需要的service.

 

2、在spring中注入action

缺点在于:

在struts.xml中写

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

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

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

     <property ref="service" />

</bean>

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

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

这一点我不是很清楚,哪位大侠能帮我推荐一下,哪种方式更合理

你可能感兴趣的:(spring,AOP,xml,struts,JUnit)