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.
Asked
Active
Viewed 1,324 times
1
-
1Have you tried to inject it? What exactly isn't working? – Aleksandr M Nov 13 '14 at 10:44
1 Answers
2
EDIT
Since there is no need to declare the Interceptor as Spring bean, I striked the unnecessary parts. Thanks to @AleksandrM for testing it.
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
<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
private DaoService daoServiceBean; // Autowired by Spring
Also read:

Konstantin
- 3,626
- 2
- 33
- 45

Andrea Ligios
- 49,480
- 26
- 114
- 243
-
1I think that should work w/o explicitly defining interceptor as a bean. – Aleksandr M Nov 13 '14 at 11:05
-
Yeah, but I wasn't sure. In the documentation is always reported ActionSupport, but in the end, the ObjectFactory is Spring... – Andrea Ligios Nov 13 '14 at 11:06
-
Then 1) he hasn't even tried in Interceptor, or 2) he has config problems preventing injection to work on Actions too. – Andrea Ligios Nov 13 '14 at 11:07