java - Spring @Autowired in Servlet -


i using spring framework (2.5.4) in app load time weaving , works fine everywhere (in spring beans, in non-spring entities), except when try autowire field in servlet annotated @configurable, nice nullpointerexception...


@configurable(dependencycheck=true) public class captchaservlet extends httpservlet{     @autowired     private captchaserviceiface captchaservice;      @override     public void init(servletconfig config) throws servletexception {         super.init(config);     //    applicationcontext ctx = webapplicationcontextutils.getrequiredwebapplicationcontext(config.getservletcontext());     //    captchaservice = (captchaserviceiface) ctx.getbean("captchaservice");     }      @override     protected void doget(httpservletrequest req, httpservletresponse resp) throws servletexception, ioexception {         captcha c = captchaservice.getcatpcha();         req.getsession().setattribute("captchaanswer", c.getanswer());         resp.setcontenttype("image/png");         imageio.write(c.getimage(), "png", resp.getoutputstream());     } } 

<context:load-time-weaver/> <context:spring-configured/> <context:component-scan base-package="cz.flexibla2" /> 

any suggestions doing incorrectly?

thanks.

see mailing list discussion , bug report @ https:// bugs.eclipse.org/bugs/show_bug.cgi?id=317874 . agree intuitively @configurable annotation on servlet should enough indicate spring framework servlet when instantiated configured spring, when using <context:spring-configured/>. have observed desired behavior achievable when using -javaagent:/path/to/aspectjweaver.jar instead of spring-instrument*.jar or spring-agent.jar. please raise issue spring jira @ https:// jira.springframework.org/browse/spr. believe problem may servlet class - not instance of servlet, class - loaded before spring contextloaderlistener called, spring framework not have chance instrument servlet class before loaded.

the spring instrumentation load-time-weaving appears based on being able transform class bytecode before loaded. if servlet container holding onto instance of class object obtained before transformed spring, (the servlet container) not able produce instances of transformed class, nor spring able instrument instances created using factory methods on class object.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -