Hi everyone,
I have a tricky problem. For some reasons I need to run an OSGi Container inside a web container (eg. Tomcat) for which I use the equinox servlet bridge. As I want to expose a service Interface over http, I use the HttpServiceExporter that exposes a service on the class "ModelFacade". I managed to register the DispatcherServlet (that I need for the remoting) from inside OSGi and let it read the spring configuration xml file. I did that like this:
The dispatcherservlet.xml file is this:Code:ServiceReference httpReference = context.getServiceReference(HttpService.class.getName()); HttpService service = (HttpService) context.getService(httpReference); DispatcherServlet servlet = new DispatcherServlet(); servlet.setContextConfigLocation("META-INF/dispatcherservlet.xml"); service.registerServlet("/remote", servlet, null, null);
I can see on the OSGi console that the servlet is able to find the configuration and loads it, now claiming that it cannot find the classes (ModelFacade) in my bundle (in which the configuration file lies, too).Code:<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:lang="http://www.springframework.org/schema/lang" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.0.xsd http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd"> <bean name="modelFacade" class="com.tp.model.ModelFacade" scope="session"> </bean> <bean name="/ModelFacade" id="modelFacadeHTTPExporter" class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter" scope="session" > <property name="service" ref="modelFacade" /> <property name="serviceInterface" value="com.tp.model.remote.IModelFacade" /> </bean> </beans>
It seems that the classloader the dispatcher servlet uses cannot see the classes in the bundle.
Here's the Tomcat-log showing the exception:
Code:13.05.2009 16:56:30 org.apache.catalina.core.AprLifecycleListener init INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not fou nd on the java.library.path: C:\Programme\Java\jdk1.6.0_11\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS; C:\Programme\Java\jdk1.6.0_11\bin;N:\COMP\PVCS\VM\win32\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\P rogramme\TortoiseSVN\bin;C:\Programme\apache-maven-2.1.0\bin 13.05.2009 16:56:30 org.apache.coyote.http11.Http11Protocol init INFO: Initializing Coyote HTTP/1.1 on http-8080 13.05.2009 16:56:30 org.apache.catalina.startup.Catalina load INFO: Initialization processed in 451 ms 13.05.2009 16:56:30 org.apache.catalina.core.StandardService start INFO: Starting service Catalina 13.05.2009 16:56:30 org.apache.catalina.core.StandardEngine start INFO: Starting Servlet Engine: Apache Tomcat/6.0.18 13.05.2009 16:56:30 org.apache.catalina.startup.HostConfig deployWAR INFO: Deploying web application archive bridge.war Listening on port 9999 ... 13.05.2009 16:56:33 org.apache.coyote.http11.Http11Protocol start INFO: Starting Coyote HTTP/1.1 on http-8080 13.05.2009 16:56:33 org.apache.jk.common.ChannelSocket init INFO: JK: ajp13 listening on /0.0.0.0:8009 13.05.2009 16:56:33 org.apache.jk.server.JkMain start INFO: Jk running ID=0 time=0/31 config=null 13.05.2009 16:56:33 org.apache.catalina.startup.Catalina start INFO: Server startup in 3074 ms 0 [OSGi Console] INFO org.springframework.osgi.extender.internal.activator.ContextLoaderListener - Starting [org.sp ringframework.osgi.extender] bundle v.[1.2.0] 94 [OSGi Console] INFO org.springframework.osgi.extender.internal.support.ExtenderConfiguration - No custom extender configuration detected; using defaults... 94 [OSGi Console] INFO org.springframework.scheduling.timer.TimerTaskExecutor - Initializing Timer 4358 [OSGi Console] INFO org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'org.springframe work.web.servlet.DispatcherServlet': initialization started 4358 [OSGi Console] INFO org.springframework.web.context.support.XmlWebApplicationContext - Refreshing org.spr ingframework.web.context.support.XmlWebApplicationContext@97d026: display name [WebApplicationContext for namespace 'org .springframework.web.servlet.DispatcherServlet-servlet']; startup date [Wed May 13 16:56:42 CEST 2009]; root of context hierarchy 4405 [OSGi Console] INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean defi nitions from ServletContext resource [/META-INF/dispatcherservlet.xml] 5467 [OSGi Console] INFO org.springframework.web.context.support.XmlWebApplicationContext - Bean factory for a pplication context [org.springframework.web.context.support.XmlWebApplicationContext@97d026]: org.springframework.beans. factory.support.DefaultListableBeanFactory@1ab2b55 5482 [OSGi Console] INFO org.springframework.beans.factory.support.DefaultListableBeanFactory - Pre-instantiat ing singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1ab2b55: defining beans [modelFac ade,modelFacadeHTTPExporter]; root of factory hierarchy 5498 [OSGi Console] INFO org.springframework.beans.factory.support.DefaultListableBeanFactory - Destroying sin gletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1ab2b55: defining beans [modelFacade,mod elFacadeHTTPExporter]; root of factory hierarchy 5498 [OSGi Console] ERROR org.springframework.web.servlet.DispatcherServlet - Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web. servlet.handler.BeanNameUrlHandlerMapping': Initialization of bean failed; nested exception is org.springframework.beans .factory.CannotLoadBeanClassException: Cannot find class [com.tp.model.ModelFacade] for bean with name 'modelFacade' def ined in ServletContext resource [/META-INF/dispatcherservlet.xml]; nested exception is java.lang.ClassNotFoundException: com.tp.model.ModelFacade at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCap ableBeanFactory.java:480) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBea nFactory.java:409) at java.security.AccessController.doPrivileged(Native Method) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapab leBeanFactory.java:380) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapab leBeanFactory.java:255) at org.springframework.web.servlet.DispatcherServlet.createDefaultStrategy(DispatcherServlet.java:770) at ...
Any ideas?


Reply With Quote