servlet如何取得spring中的bean,这只是其中一种方法。
但是有点不解的是,spring的bean的name不是按照第一个大写字母小写的命名的么,怎么我这里的SQLServiceImpl还是SQLServiceImpl?
但是有点不解的是,spring的bean的name不是按照第一个大写字母小写的命名的么,怎么我这里的SQLServiceImpl还是SQLServiceImpl?
public class BatchDownload extends HttpServlet {
@Autowired(required=true)
private SQLService service;
public BatchDownload() {
super();
}
@Override
public void init() throws ServletException {
super.init();
ServletContext servletContext = this.getServletContext();
WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(servletContext);
service = (SQLService)ctx.getBean("SQLServiceImpl");
}
}