【发布时间】:2015-10-16 20:29:02
【问题描述】:
我嵌入了 Jetty 服务器并添加了 servlet 映射。
ServletContextHandler context = new ServletContextHandler();
context.setContextPath("/");
context.addServlet(RegisterServlet.class, "/user/register");
我想用spring框架配置ApplicationContext.xml在servlet中进行依赖注入。它应该和这里一样工作:
public class RegisterServlet extends HttpServlet {
private Service service;
@Override
public void init() throws ServletException {
super.init();
ApplicationContext context = new ClassPathXmlApplicationContext("ApplicationContext.xml");
service = context.getBean("service", Service.class);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
...
}
但不使用 context.getBean("service")。
【问题讨论】: