如何将springbean注入struts拦截器..有可能吗 [英] how to inject springbean to a struts intercepter..is it possible
问题描述
我有一个使用定义的拦截器,从拦截器我想通过 DAO 层进行 db 调用,那么如何将 spring bean 注入到 struts 拦截器.是否可以将 spring bean 注入到 struts 拦截器任何人都可以对此提出任何想法.
I am having a used defined intercepter,from the intercepter i want to make a db call through DAO layer, so how can i inject spring bean to struts intercepter.is it possible to inject spring bean to a struts intercepter can any one suggest any idea on this.
推荐答案
编辑
由于不需要将 Interceptor 声明为 Spring bean,因此我删除了不必要的部分.感谢@AleksandrM 对其进行测试.
Since there is no need to declare the Interceptor as Spring bean, I striked the unnecessary parts. Thanks to @AleksandrM for testing it.
与 Actions 完全一样,除了(如果我没记错的话)在 beans.xml 中声明它的例外,因为拦截器不扩展 ActionSupport(默认情况下是自动装配的).
Exactly the way you do with Actions , with (if I remember well) the exception of declaring it in beans.xml because Interceptors don't extend ActionSupport (that is autowired by default) .
web.xml
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
ApplicationContext.xml
ApplicationContext.xml
<bean id="daoServiceBean"
class="org.foo.bar.business.dao.DaoService"/>
<罢工>
<bean id="myInterceptorBean"
class="org.foo.bar.presentation.interceptors.MyInterceptor"/>
Struts.xml
<constant name="struts.objectFactory" value="spring" />
<package ...>
<interceptors>
<罢工>
<interceptor name="myInterceptor" class="myInterceptorBean" />
<interceptor name="myInterceptor"
class="org.foo.bar.presentation.interceptors.MyInterceptor"/>
MyInterceptor.java
MyInterceptor.java
private DaoService daoServiceBean; // Autowired by Spring
另请阅读:
这篇关于如何将springbean注入struts拦截器..有可能吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!