Deploying a servlet programmatically with Jetty Deploying a servlet programmatically with Jetty spring spring

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.