Nous utilisons spring pour configurer jetty et charger tout, et j'essaie d'utiliser jersey pour les services web et d'utiliser la bibliothèque jetty/spring que je peux autowire certaines classes de service dans mes ressources de maillot, mais j'ai des difficultés à démarrer le serveur parce qu'il dit toujours que le ServletContext
est nul.ServletContext est null lors de l'utilisation de spring pour charger jetty avec jersey/jax-ws
Voici mon xml config printemps:
<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>
J'ai suivi les instructions ici: http://blogs.oracle.com/enterprisetechtips/entry/jersey_and_spring pour intégrer le maillot et au printemps, mais la différence est que je suis un serveur de jetée intégré configuré avec ressort.
Je ne suis pas sûr pourquoi je continue à obtenir l'erreur suivante. Je pensais que la jetée ServletContextHandler était le contexte de servlet de leur 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 for root resource and provider classes in the 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 from 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 be null**
at org.springframework.util.Assert.notNull(Assert.java:112)
at org.springframework.web.context.support.WebApplicationContextUtils.getWebApplicationContext(WebApplicationContextUtils.java:96)
at org.springframework.web.context.support.WebApplicationContextUtils.getWebApplicationContext(WebApplicationContextUtils.java:86)
at org.springframework.web.context.support.WebApplicationContextUtils.getRequiredWebApplicationContext(WebApplicationContextUtils.java:68)
at com.sun.jersey.spi.spring.container.servlet.SpringServlet.getDefaultContext(SpringServlet.java:128)
at com.sun.jersey.spi.spring.container.servlet.SpringServlet.getChildContext(SpringServlet.java:119)
at com.sun.jersey.spi.spring.container.servlet.SpringServlet.getContext(SpringServlet.java:113)
at com.sun.jersey.spi.spring.container.servlet.SpringServlet.initiate(SpringServlet.java:99)
at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:253)
at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:521)
at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:199)
at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:308)
at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:471)
at javax.servlet.GenericServlet.init(GenericServlet.java:241)
at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:421)
at org.eclipse.jetty.servlet.ServletHolder.doStart(ServletHolder.java:245)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55)
at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:699)
at org.eclipse.jetty.servlet.ServletHandler.doStart(ServletHandler.java:155)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55)
at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:165)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55)
at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:92)
at org.eclipse.jetty.server.Server.doStart(Server.java:228)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1414)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1375)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
at com.mycompany.common.service.SpringServiceImpl.startService(SpringServiceImpl.java:52)
at com.traveladnetwork.common.service.StartImpl.run(StartImpl.java:42)
at java.lang.Thread.run(Thread.java:637)
2010-11-30 23:19:05.412:INFO::Started [email protected]:9932
2010-11-30 23:19:05,413 [Thread-0] INFO [com.mycompany.common.service.StartImpl]: Started in 1950 ms