Hi,
I guess, my question is pretty simple... Is there are way to use @Autowire for a component declared with @Service inside a servlet?
Service implementation example:
Servlet example:Code:@Service public class MyService implements Service { public String test() { return "test"; } }
Since servlets have their own lifecycle of instantiation, initialization, etc., which is certainly different from Spring, it seems that this would not be possible...Code:public class MyServlet extends HttpServlet { @Autowired private Service service; public void doGet(.........) { System.out.print(service.test()); } }
However, perhaps, I am overlooking something here and maybe Spring can plug into the servlet lifecycle to make sure the @Autowired actually works.
I've tried the example pretty much as is and the 'service' is null. (I did use the Spring-provided ContextLoaderListener and configured it in web.xml).
Any suggestions?
Thanks,
Yaakov.


Reply With Quote
)