How to connect HttpServlet with Spring Application Context in web.xml?

I found a way to inject Beans in my HttpServlet ( Note: I don't need a Presentation View, otherwise there are more advanced Spring Classes).

I found a way to inject Beans in my HttpServlet (Note: I don't need a Presentation View, otherwise there are more advanced Spring Classes) Add a ContextLoaderListener to web. Xml so that Spring's root WebApplicationContext is loaded org.springframework.web.context. ContextLoaderListener Configure Servlet using Springs HttpRequestHandlerServlet Class FooServlet Foo Servlet org.springframework.web.context.support.

HttpRequestHandlerServlet Let your Servlet implement the org.springframework.web. HttpRequestHandler Interface Define your Servlet as a Bean in ApplicationContext (beanID must be same as ). Now it's possible to inject all necassary Beans in the Spring DependencyInjection way without dependency lookup.

... I have an HttpServlet that I need to initialize data and I need to call it when my app is deployed. It's been quite a problem for me. Any thoughts?

– Brian L. Apr 18 at 4:45.

I think you should use Spring utilities like RequestContextUtils. GetWebApplicationContext(request, application); to hookup the Spring Context within your Servlet. Agreed this is no DI/IoC, but the servlet is no bean as well!

Martin Dürrmeiers answer confirmed at springsource forum.springsource.org/showthread.php?t=....

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions