servlets - undertow + Spring WebApplicationInitializer - Double initialization -
i migrating old web app. written old web.xml
-style, want programmatically build servlet.
this spring mvc app, deployed war module in ear under wildfly 10.0.0.final.
i wrote implementation of spring's webapplicationinitializer
(still using spring xml config @ moment, preceed step step - next step migrate javaconfig). though i'm stuck here because servlet initialized twice, , second time initilization fails due filter's name conflict - nullpointerexception
after filter creation.
this initilizer:
public class mywebapplicationinitializer implements webapplicationinitializer { private static final logger log = loggerfactory.getlogger(mywebapplicationinitializer.class); /** * @see org.springframework.web.webapplicationinitializer#onstartup(javax.servlet.servletcontext) */ @override public void onstartup(servletcontext container) throws servletexception { log.debug("******* initializing web app *******"); xmlwebapplicationcontext rootcontext = new xmlwebapplicationcontext(); rootcontext.setconfiglocation("classpath:meta-inf/spring/application-context.xml"); xmlwebapplicationcontext webcontext = new xmlwebapplicationcontext(); webcontext.setconfiglocation("classpath:meta-inf/spring/mvc-context.xml"); container.addlistener(new contextloaderlistener(rootcontext)); servletregistration.dynamic dispatcher = container.addservlet("dispatcher", new dispatcherservlet(webcontext)); dispatcher.setloadonstartup(1); dispatcher.addmapping("/"); container.addfilter("log4jenhancementfilter", log4jenhancementfilter.class); log.info("******* web app correctly initialized *******"); } }
a bit of log below:
[serverservice thread pool -- 74]:[info] @ 2016-04-19 07:19:27,725: io.undertow.servlet.spec.servletcontextimpl.log:313: spring webapplicationinitializers detected on classpath: [com.xyz.web.servlet.mywebapplicationinitializer@6356dd91] [serverservice thread pool -- 74]:[debug] @ 2016-04-19 07:19:27,725: com.xyz.web.servlet.mywebapplicationinitializer.onstartup:44: ******* initializing web app ******* ... [serverservice thread pool -- 74]:[info] @ 2016-04-19 07:19:27,796: com.xyz.web.servlet.mywebapplicationinitializer.onstartup:59: ******* web app correctly initialized ******* ... [serverservice thread pool -- 74]:[info] @ 2016-04-19 07:19:27,797: io.undertow.servlet.spec.servletcontextimpl.log:313: spring webapplicationinitializers detected on classpath: [com.xyz.web.servlet.mywebapplicationinitializer@427d3c64] [serverservice thread pool -- 74]:[debug] @ 2016-04-19 07:19:27,797: com.xyz.web.servlet.mywebapplicationinitializer.onstartup:44: ******* initializing web app ******* 07:19:27,800 error [org.jboss.msc.service.fail] (serverservice thread pool -- 74) msc000001: failed start service jboss.undertow.deployment.default-server.default-host./www: org.jboss.msc.service.startexception in service jboss.undertow.deployment.default-server.default-host./www: java.lang.runtimeexception: java.lang.nullpointerexception @ org.wildfly.extension.undertow.deployment.undertowdeploymentservice$1.run(undertowdeploymentservice.java:85) @ java.util.concurrent.executors$runnableadapter.call(executors.java:511) @ java.util.concurrent.futuretask.run(futuretask.java:266) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1142) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:617) @ java.lang.thread.run(thread.java:745) @ org.jboss.threads.jbossthread.run(jbossthread.java:320) caused by: java.lang.runtimeexception: java.lang.nullpointerexception @ io.undertow.servlet.core.deploymentmanagerimpl.deploy(deploymentmanagerimpl.java:231) @ org.wildfly.extension.undertow.deployment.undertowdeploymentservice.startcontext(undertowdeploymentservice.java:100) @ org.wildfly.extension.undertow.deployment.undertowdeploymentservice$1.run(undertowdeploymentservice.java:82) ... 6 more caused by: java.lang.nullpointerexception @ com.xyz.web.servlet.mywebapplicationinitializer.onstartup(mywebapplicationinitializer.java:54) @ org.springframework.web.springservletcontainerinitializer.onstartup(springservletcontainerinitializer.java:175) @ io.undertow.servlet.core.deploymentmanagerimpl.deploy(deploymentmanagerimpl.java:184) ... 8 more
as can see there double servlet's initilization; first succeeds, second fails due npe
.
what doing wrong , how can fix it?
Comments
Post a Comment