我在我的应用程序中使用带有加载时间编织的 Spring 框架(2.5.4),并且在任何地方(在 Spring bean 中,在非 Spring 实体中)一切正常,除非我尝试在注释为 @Configurable 的 servlet 中自动装配字段,然后我得到一个很好的 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" />
关于我做错了什么有什么建议吗?
谢谢。