ServletContext is null when using spring to load jetty with jersey/jax-ws -
we're using spring configure jetty , load up, , i'm trying use jersey web services , use jetty/spring library can autowire service classes jersey resources, i'm having trouble starting server because says servletcontext
null.
here's spring config xml:
<property name="handler"> <bean id="handlers" class="org.eclipse.jetty.server.handler.handlerlist"> <property name="handlers"> <list> <bean class="org.eclipse.jetty.servlet.servletcontexthandler"> <property name="eventlisteners"> <list> <bean class="org.springframework.web.context.contextloaderlistener" /> <bean class="org.springframework.web.context.request.requestcontextlistener" /> </list> </property> <property name="initparams"> <map> <entry> <key> <value>contextconfiglocation</value> </key> <value>classpath:applicationcontext.xml</value> </entry> </map> </property> </bean> <bean class="org.eclipse.jetty.servlet.servlethandler"> <property name="servlets"> <list> <bean class="org.eclipse.jetty.servlet.servletholder"> <property name="name" value="jersey" /> <property name="servlet"> <bean class="com.sun.jersey.spi.spring.container.servlet.springservlet" /> </property> <property name="initparameters"> <map> <entry> <key> <value>com.sun.jersey.config.property.packages</value> </key> <value>com.mycompany.ws.resource</value> </entry> <entry> <key> <value>contextconfiglocation</value> </key> <value>classpath:applicationcontext.xml</value> </entry> </map> </property> </bean> </list> </property>
i followed instructions here: http://blogs.oracle.com/enterprisetechtips/entry/jersey_and_spring integrate jersey , spring, difference have embedded jetty server configured spring.
i'm not sure why keep getting following error. thought jetty servletcontexthandler servlet context documentation.
2010-11-30 23:19:05,177 [thread-0] info [org.springframework.web.context.contextloader]: root webapplicationcontext: initialization completed in 177 ms nov 30, 2010 11:19:05 pm com.sun.jersey.api.core.packagesresourceconfig init info: scanning root resource , provider classes in packages: com.traveladnetwork.ws.resource.ad.server nov 30, 2010 11:19:05 pm com.sun.jersey.api.core.packagesresourceconfig init info: root resource classes found: class com.mycompany.ws.resource.targetresource class com.mycompany.ws.resource.reportresource class com.mycompany.ws.resource.helloworldresource nov 30, 2010 11:19:05 pm com.sun.jersey.api.core.packagesresourceconfig init info: provider classes found: nov 30, 2010 11:19:05 pm com.sun.jersey.spi.spring.container.servlet.springservlet getcontext info: creating new child context classpath:applicationcontext.xml nov 30, 2010 11:19:05 pm com.sun.jersey.spi.spring.container.servlet.springservlet initiate **severe: exception occurred when intialization java.lang.illegalargumentexception: servletcontext must not null** @ org.springframework.util.assert.notnull(assert.java:112) @ org.springframework.web.context.support.webapplicationcontextutils.getwebapplicationcontext(webapplicationcontextutils.java:96) @ org.springframework.web.context.support.webapplicationcontextutils.getwebapplicationcontext(webapplicationcontextutils.java:86) @ org.springframework.web.context.support.webapplicationcontextutils.getrequiredwebapplicationcontext(webapplicationcontextutils.java:68) @ com.sun.jersey.spi.spring.container.servlet.springservlet.getdefaultcontext(springservlet.java:128) @ com.sun.jersey.spi.spring.container.servlet.springservlet.getchildcontext(springservlet.java:119) @ com.sun.jersey.spi.spring.container.servlet.springservlet.getcontext(springservlet.java:113) @ com.sun.jersey.spi.spring.container.servlet.springservlet.initiate(springservlet.java:99) @ com.sun.jersey.spi.container.servlet.servletcontainer$internalwebcomponent.initiate(servletcontainer.java:253) @ com.sun.jersey.spi.container.servlet.webcomponent.load(webcomponent.java:521) @ com.sun.jersey.spi.container.servlet.webcomponent.init(webcomponent.java:199) @ com.sun.jersey.spi.container.servlet.servletcontainer.init(servletcontainer.java:308) @ com.sun.jersey.spi.container.servlet.servletcontainer.init(servletcontainer.java:471) @ javax.servlet.genericservlet.init(genericservlet.java:241) @ org.eclipse.jetty.servlet.servletholder.initservlet(servletholder.java:421) @ org.eclipse.jetty.servlet.servletholder.dostart(servletholder.java:245) @ org.eclipse.jetty.util.component.abstractlifecycle.start(abstractlifecycle.java:55) @ org.eclipse.jetty.servlet.servlethandler.initialize(servlethandler.java:699) @ org.eclipse.jetty.servlet.servlethandler.dostart(servlethandler.java:155) @ org.eclipse.jetty.util.component.abstractlifecycle.start(abstractlifecycle.java:55) @ org.eclipse.jetty.server.handler.handlercollection.dostart(handlercollection.java:165) @ org.eclipse.jetty.util.component.abstractlifecycle.start(abstractlifecycle.java:55) @ org.eclipse.jetty.server.handler.handlerwrapper.dostart(handlerwrapper.java:92) @ org.eclipse.jetty.server.server.dostart(server.java:228) @ org.eclipse.jetty.util.component.abstractlifecycle.start(abstractlifecycle.java:55) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:39) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:25) @ java.lang.reflect.method.invoke(method.java:597) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.invokecustominitmethod(abstractautowirecapablebeanfactory.java:1414) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.invokeinitmethods(abstractautowirecapablebeanfactory.java:1375) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.initializebean(abstractautowirecapablebeanfactory.java:1335) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:473) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory$1.run(abstractautowirecapablebeanfactory.java:409) @ java.security.accesscontroller.doprivileged(native method) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:380) @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:264) @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:222) @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:261) @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:185) @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:164) @ org.springframework.beans.factory.support.defaultlistablebeanfactory.preinstantiatesingletons(defaultlistablebeanfactory.java:429) @ org.springframework.context.support.abstractapplicationcontext.finishbeanfactoryinitialization(abstractapplicationcontext.java:728) @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:380) @ com.mycompany.common.service.springserviceimpl.startservice(springserviceimpl.java:52) @ com.traveladnetwork.common.service.startimpl.run(startimpl.java:42) @ java.lang.thread.run(thread.java:637) 2010-11-30 23:19:05.412:info::started selectchannelconnector@0.0.0.0:9932 2010-11-30 23:19:05,413 [thread-0] info [com.mycompany.common.service.startimpl]: started in 1950 ms
it because you're running servlet container within spring (rather other way around) can't find servletcontext.
you've got 2 options:
- try starting jetty programmatic bootstrap loads spring inside it's servlet context (deploying servlet programmatically jetty)
- split applicationcontext.xml 2 container definitions: needed start jetty , can't start without valid servletcontext. ones need valid servlet context should in "initparams" bean class "servletcontexthandler", whereas you've got same applicationcontext.xml defined twice.
Comments
Post a Comment