eclipse - WebApplicationInitializer container.addServlet() returns null -
i creating basic web app maven, importing eclipse 4.2. have tomcat 7 setup server. trying configure spring data mongodb web app.
i following code-based configuration approach found here: webapplicationinitializer
when run project on server, null pointer exception in webapplicationinitializer class have created. line: container.addservlet("dispatcher", new dispatcherservlet(dispatchercontext)); returning null.
what heck missing? bit new creating web-apps scratch using annotations.
here class in question:
public class atwwebappinitializer implements webapplicationinitializer { @override public void onstartup(servletcontext container) throws servletexception { // create 'root' spring application context annotationconfigwebapplicationcontext rootcontext = new annotationconfigwebapplicationcontext(); rootcontext.register(springmongoconfig.class); // manage lifecycle of root application context container.addlistener(new contextloaderlistener(rootcontext)); // create dispatcher servlet's spring application context annotationconfigwebapplicationcontext dispatchercontext = new annotationconfigwebapplicationcontext(); dispatchercontext.register(atwdispatcherconfig.class); // register , map dispatcher servlet servletregistration.dynamic dispatcher = container.addservlet("dispatcher", new dispatcherservlet(dispatchercontext)); dispatcher.setloadonstartup(1); dispatcher.addmapping("/*"); } }
tried adding pom:
<dependency> <groupid>javax.servlet</groupid> <artifactid>javax.servlet-api</artifactid> <version>3.0.1</version> <scope>provided</scope> </dependency>
didn't change anything, still getting npe. read here (http://docs.oracle.com/javaee/6/api/javax/servlet/servletcontext.html) container.addservlet returns null if servlet registered? tomcat registering servlet already?
apologies wasting everyone's time, i had web.xml file registering same servlet. 1 returning null. on fixing 404, screwed controller somehow.
according servletcontext javadoc method addservlet() return null if servlet specified name registered.
Comments
Post a Comment