java - Failing to @AutoWire a member in a @WebServlet -


i can't seem servlet's fields @autowire; end null. have pure annotation-configured webapp (no xml files). servlet looks this:

@webservlet("/service") public class satdbhessianservlet     extends httpservlet {     @autowired  protected   newsitemdao             mnewsitemdao; } 

other @autowired things seem work fine, both @service objects , @repository objects. not one, , can't figure out why. tried adding package componentscan(basepackages) list other classes.

additional info:

i added following servlet’s init() method, , seemed wire properly, i'm confused why spring can't wire without that.

springbeanautowiringsupport.processinjectionbasedonservletcontext(this, inconfig.getservletcontext()); 

servlet web components not being created spring container, based on lifecycle not managed container , lot of stuff spring provides such autowired or aspect can not run them.

you need indicate spring container component created outside of ioc container , need part of it.

and api said springbeanautowiringsupport for:

convenient base class self-autowiring classes gets constructed within spring-based web application

this generic servlet base class has no dependency on spring applicationcontext concept.

there way indicate servlets being created spring container using interface


Comments