Back Forum Reply New

Injecting beans into a web service implementation

Hello all,

I running into an issue with injecting a service into my web service implementation.  The setup is Spring dm Server version 1.0.2 and jax-ws-spring-1.8.

I have two bundles, A and B.  Bundle A is publishing a out a service named 'importService'.  Bundle B, which is the web service bundle, uses that service, or at least, that is the intent.

Bundle B's setup is as follows:

WEB-INF/web.xml - Code:
lt;web-appgt;
lt;context-paramgt;
lt;param-namegt;contextConfigLocationlt;/param-namegt;
lt;param-valuegt;
/META-INF/spring/bundle-context-osgi.xml
/WEB-INF/applicationContext.xml
lt;/param-valuegt;
lt;/context-paramgt;
lt;listenergt;
lt;listener-classgt;org..web.context.ContextLoaderListenerlt;/listener-classgt;
lt;/listenergt;
lt;servletgt;
lt;servlet-namegt;TestAPIWSlt;/servlet-namegt;
lt;servlet-classgt;com.sun.xml.ws.transport.from.servlet.WSSpringServletlt;/servlet-classgt;
lt;load-on-startupgt;1lt;/load-on-startupgt;
lt;/servletgt;
lt;servlet-mappinggt;
lt;servlet-namegt;TestAPIWSlt;/servlet-namegt;
lt;ucl-patterngt;/TestAPIWSlt;/ucl-patterngt;
lt;/servlet-mappinggt;
lt;/web-appgt;
WEB-INF/applicationContext.xml -Code:
lt;beans xmlns=quot;schema/beansquot;
xmlns:xsi=quot;2001/XMLSchema-instancequot;
xmlns:ws=quot;spring/corequot;
xmlns:wss=quot;spring/servletquot;
xsi:schemaLocation=quot;schema/beans schema/beans/spring-beans.xsd
spring/core spring/core.xsd
spring/servlet spring/servlet.xsdquot;
gt;
lt;wss:binding ucl=quot;/TestAPIWSquot;gt;
lt;wss:servicegt;
lt;ws:service bean=quot;#TestAPIWSquot; /gt;
lt;/wss:servicegt;
lt;/wss:bindinggt;

lt;bean id=quot;TestAPIWSquot; class=quot;com.test.webservices.TestImplAPIWSquot;gt;
lt;property name=quot;importServicequot; ref=quot;importServicequot; /gt;
lt;/beangt;
lt;/beansgt;
META-INF/spring/bundle-context-osgi.xml -Code:
lt;beans:beans
xmlns=quot;schema/osgiquot;
xmlns:xsi=quot;2001/XMLSchema-instancequot;
xmlns:beans=quot;schema/beansquot;
xmlnssgi=quot;schema/osgiquot;
xsi:schemaLocation=quot;
schema/osgi
schema/osgi/spring-osgi.xsd
schema/beans
schema/beans/spring-beans.xsd
quot;
gt;
lt;reference id=quot;importServicequot; interface=quot;com.test.domain.Importquot; /gt;
lt;/beans:beansgt;
The error message I get is as follows:Code:
org..beans.factory.BeanCreationException: Error creating bean with name 'importService': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Required 'bundleContext' property was not set.
at org..beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1338)
at org..beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473)
at org..beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org..beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org..beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
at org..beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org..beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
at org..beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
at org..beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org..beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:423)
at org..context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
at org..context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
at org..web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)
at org..web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
at org..web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3843)
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 com..server.servlet.tomcat.TomcatServletContainer.addContext(TomcatServletContainer.java:954)
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..aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
at org..osgi.service.importer.support.internal.aop.ServiceInvoker.doInvoke(ServiceInvoker.java:58)
at org..osgi.service.importer.support.internal.aop.ServiceInvoker.invoke(ServiceInvoker.java:62)
at org..aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org..aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131)
at org..aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119)
at org..aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org..osgi.service.importer.support.LocalBundleContextAdvice.invoke(LocalBundleContextAdvice.java:59)
at org..aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org..aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131)
at org..aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119)
at org..aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org..aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy92.addContext(Unknown Source)
at com..server.web.core.WebModulePersonality.deploy(WebModulePersonality.java:393)
at com..server.deployer.core.module.AbstractModule.deploy(AbstractModule.java:235)
at com..server.deployer.core.module.StandardModule.onStarted(StandardModule.java:572)
at com..server.deployer.core.module.DeployerBundleListener$2$1.run(DeployerBundleListener.java:148)
at com..server.concurrent.core.ExecutorServiceDelegate$StatisticsGatheringRunnable.run(ExecutorServiceDelegate.java:137)
at com..server.concurrent.core.ServerThreadPoolExecutor$1.run(ServerThreadPoolExecutor.java:145)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.IllegalArgumentException: Required 'bundleContext' property was not set.
at org..util.Assert.notNull(Assert.java:112)
at org..osgi.service.importer.support.AbstractOsgiServiceImportFactoryBean.afterPropertiesSet(AbstractOsgiServiceImportFactoryBean.java:79)
at org..osgi.service.importer.support.AbstractServiceImporterProxyFactoryBean.afterPropertiesSet(AbstractServiceImporterProxyFactoryBean.java:49)
at org..osgi.service.importer.support.OsgiServiceProxyFactoryBean.afterPropertiesSet(OsgiServiceProxyFactoryBean.java:118)
at org..beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1369)
at org..beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335)
... 48 more
It seems to be a configuration issue but not matter what I try, I can't seem to make it work.

Now, I have verified that the published service can get injected by creating a test class on the web service side and have its bean property get injected with the importService class.  The test consisted of adding the following file and debugging within the SpringSource Tool Suite and verifying the setter method was called.

At this point, I don't know where to look.  Is this the correct way of injecting beans into web service implementations?  Any ideas would be greatly appreciated.

Thanks!
Mauro

To make use of the osgi namespace and its lt;servicegt; and lt;referencegt; tags, you need to ensure that your application context is OSGi-aware. You can do this by setting a context-param in your web.xml that tells the ContextLoaderListener which class it should instantiate when creating the application context:Code:
lt;context-paramgt; lt;param-namegt;contextClasslt;/param-namegt; lt;param-valuegt;com..server.web.dm.ServerOsgiBundleXmlWebApplicationContextlt;/param-valuegt;
lt;/context-paramgt;
There's some more information about this in section 5.2.4 of the programmers guide. An alternative option is to use a Web module. Web modules' application contexts are, by default, OSGi aware. You can find some more information about this in section 5.2.3.

That was it!  I've been trying to get this to work for days and it turns out to be something so simple.  I re-read those sections of the programmers guide and hopefully this time it'll make more sense.

Thanks for helping a newbie!
Mauro
¥
Back Forum Reply New