Another question on Spring 3, servlet, @autowired -


I think I have read every question and have repeated the answer on the spring and a servlet, both here and springsource.org But I still can not get this work.

What I want to do is that Datastro is automatically set in my servletlet, I think the container creates a serial and not a spring.

Here is the code from my test servlet:

  package mypackage.servlets; Import goes here ... @Service Public Class Test Services HTTP Servlet {Private JDBC Template _jt; @ Owned Public Zero Sat Datasource (DataSource Data Source) {_jt = New JDBC Template (Datasource); } e.t.c.   

I have in my applicationContext.xml:

  & lt; Context: annotation-config / & gt; & Lt; Context: component-scan base-package = "mypackage.servlets />    

and in my data source.xml :

  & lt; jee: jndi-lookup id = "dataSource" jndi-name = "java: comp / env / jdbc / db" />   

If I can not get this work, then I will only use WebApplicationContextUtils in the inlet method of the servlet, but after doing all this I really want to do what I have done.

I'm using Spring 3, Java 1.6.

Thanks

Paul

You need to change your Servlets by Spring MVC contollers because Spring will not inject anything (except the @Configurable) Spring itselfe (servlet) made by any other. < P> (Take a look at a very simple example, STS Spring Template Project: MVC).

Comments