You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Jeff Walker <we...@gmail.com> on 2008/12/16 20:13:52 UTC
javax.naming.NameNotFoundException when service implementation class tries to implement javax.servlet.ServletContextListener
Hi,
I have a web service using JAX-WS 2.1 with CXF 2.0.6. It's an elementary
service with one operation, but it works fine. Now, I want to add Spring
support. I want to get the Spring application's context, by calling this:
*ApplicationContext appContext =
WebApplicationContextUtils.getWebApplicationContext( ?? ServletContext ??);*
So, I thought I'd make my service implementation class implement the
ServletContextListener interface, implement the contextInitialized() and
contextDestroyed() methods, and voila! I would have a servletContext to pass
into
getWebApplicationContext() above. I could then get the Spring context very
early in my services lifecycle. I registered the listener class in my
web.xml file and it all seems good to me. But, when I deploy my
Maven-created war to Tomcat 6.0.18, I get:
Dec 16, 2008 1:37:40 PM org.apache.catalina.core.StandardContext
listenerStart
SEVERE: Error configuring application listener of class
com.mycompany.service.TestWebServicePortImpl
javax.naming.NameNotFoundException: Name
com.mycompany.service.TestWebServicePortImpl is not bound in this Context
at org.apache.naming.NamingContext.lookup(NamingContext.java:770)
at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
at
org.apache.catalina.util.DefaultAnnotationProcessor.lookupFieldResource(DefaultAnnotationProcessor.java:208)
at
org.apache.catalina.util.DefaultAnnotationProcessor.processAnnotations(DefaultAnnotationProcessor.java:138)
at
org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3790)
at
org.apache.catalina.core.StandardContext.start(StandardContext.java:4342)
at
org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at
org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:830)
at
org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:719)
at
org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:490)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1149)
at
org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
at
org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at
org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at
org.apache.catalina.core.StandardService.start(StandardService.java:516)
at
org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
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.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Dec 16, 2008 1:37:40 PM org.apache.catalina.core.StandardContext
listenerStart
SEVERE: Skipped installing application listeners due to previous error(s)
Dec 16, 2008 1:37:40 PM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: contextInitialized()
Dec 16, 2008 1:37:40 PM org.apache.catalina.core.ApplicationContext log
INFO: SessionListener: contextInitialized()
Incidentally, when I attempted the same thing in Metro (Glassfish/NetBeans),
it worked fine. The service implementation class can indeed implement the
ServletContextListener interface as long as you register your class as a
listener in web.xml.
Can I not do this with CXF?
Any hints please would be greatly appreciated.
Thanks,
Jeff Walker
Re: javax.naming.NameNotFoundException when service implementation class tries to implement javax.servlet.ServletContextListener
Posted by Daniel Kulp <dk...@apache.org>.
This LOOKS like a tomcat issue or similar since there isn't anything in there
related to Spring or CXF. Are there fields on your TestWebServicePortImpl
that have any annotations on them, like @Resource or similar?
The other way to do this would be to make your bean ApplicationContextAware
(it's a spring interface). Spring will then set the ApplicationContext on
your bean itself. You wouldn't define the bean in the web.xml, just in your
spring xml file.
Dan
On Tuesday 16 December 2008 2:13:52 pm Jeff Walker wrote:
> Hi,
> I have a web service using JAX-WS 2.1 with CXF 2.0.6. It's an elementary
> service with one operation, but it works fine. Now, I want to add Spring
> support. I want to get the Spring application's context, by calling this:
> *ApplicationContext appContext =
> WebApplicationContextUtils.getWebApplicationContext( ?? ServletContext
> ??);*
>
> So, I thought I'd make my service implementation class implement the
> ServletContextListener interface, implement the contextInitialized() and
> contextDestroyed() methods, and voila! I would have a servletContext to
> pass into
> getWebApplicationContext() above. I could then get the Spring context very
> early in my services lifecycle. I registered the listener class in my
> web.xml file and it all seems good to me. But, when I deploy my
> Maven-created war to Tomcat 6.0.18, I get:
>
> Dec 16, 2008 1:37:40 PM org.apache.catalina.core.StandardContext
> listenerStart
> SEVERE: Error configuring application listener of class
> com.mycompany.service.TestWebServicePortImpl
> javax.naming.NameNotFoundException: Name
> com.mycompany.service.TestWebServicePortImpl is not bound in this Context
> at org.apache.naming.NamingContext.lookup(NamingContext.java:770)
> at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
> at
> org.apache.catalina.util.DefaultAnnotationProcessor.lookupFieldResource(Def
>aultAnnotationProcessor.java:208) at
> org.apache.catalina.util.DefaultAnnotationProcessor.processAnnotations(Defa
>ultAnnotationProcessor.java:138) at
> org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java
>:3790) at
> org.apache.catalina.core.StandardContext.start(StandardContext.java:4342)
> at
> org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:
>791) at
> org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
> at
> org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525) at
> org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:830) at
> org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:719)
> at
> org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:490)
> at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1149)
> at
> org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
> at
> org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSuppo
>rt.java:117) at
> org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053) at
> org.apache.catalina.core.StandardHost.start(StandardHost.java:719) at
> org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045) at
> org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
> at
> org.apache.catalina.core.StandardService.start(StandardService.java:516)
> at
> org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
> at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:3
>9) at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImp
>l.java:25) at java.lang.reflect.Method.invoke(Method.java:597)
> at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
> at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
> Dec 16, 2008 1:37:40 PM org.apache.catalina.core.StandardContext
> listenerStart
> SEVERE: Skipped installing application listeners due to previous error(s)
> Dec 16, 2008 1:37:40 PM org.apache.catalina.core.ApplicationContext log
> INFO: ContextListener: contextInitialized()
> Dec 16, 2008 1:37:40 PM org.apache.catalina.core.ApplicationContext log
> INFO: SessionListener: contextInitialized()
>
>
> Incidentally, when I attempted the same thing in Metro
> (Glassfish/NetBeans), it worked fine. The service implementation class can
> indeed implement the ServletContextListener interface as long as you
> register your class as a listener in web.xml.
> Can I not do this with CXF?
> Any hints please would be greatly appreciated.
>
> Thanks,
> Jeff Walker
--
Daniel Kulp
dkulp@apache.org
http://dankulp.com/blog