servletでspringのbeanを取得する
servletがspringのbeanをどのように取得するかは、その1つの方法にすぎません.
しかし、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");
}
}