Deploying a servlet programmatically with Jetty
For those who are interested, I got this to work as follows:
Server server = new Server(8090);ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);context.setContextPath("/batch");// Setup Spring contextcontext.addEventListener(new ContextLoaderListener());context.setInitParameter("contextConfigLocation", "classpath*:**/testContext.xml");server.setHandler(context);// Add servletscontext.addServlet(new ServletHolder(new BatchReceiver()), "/receiver/*");context.addServlet(new ServletHolder(new BatchSender()), "/sender/*"); server.start();server.join();
The key step I was missing was
context.addEventListener(new ContextLoaderListener());
which loads the Spring context.
if you want to process a web.xml you need to use a WebappContext, a servlet context doesn't know anything about web.xml's