如何将springbean注入到struts拦截器中 [英] how to inject springbean to a struts intercepter..is it possible

查看:139
本文介绍了如何将springbean注入到struts拦截器中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个已使用的定义的拦截器,我想从拦截器中通过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.

与操作完全一样,但(如果我还记得的话)在bean.xml中声明它的例外,因为Interceptor不会扩展ActionSupport(默认情况下是自动连接的).

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

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

又读:

  • Spring Plugin
  • Spring and Struts2

这篇关于如何将springbean注入到struts拦截器中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆