I am using Struts2 with Spring for dependency injections.
I have Struts action A
from which I can access HttpServletRequest
and some dependency B
inside it:
public class A extends ActionSupport implements ServletRequestAware {
private B b;
private HttpServletRequest request;
@Override
public void setServletRequest(HttpServletRequest httpServletRequest)
{
this.httpServletRequest = httpServletRequest;
}
public B getB() {
return this.b;
}
public void setB(B b) {
this.b = b;
}
}
There is also application-context.xml
:
<bean id="b" class="com.example.B" />
<bean id="a" class="com.example.actions.A">
<property name="b" ref="b" />
</bean>
The program works, but here is my problem: dependency B
requires HttpServletRequest
to function properly. Is there a way for Spring to inject it in B
? Right now I would need to pass HttpServletRequest
object manually to methods that require it.