Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Virgo » Reference bean in application context from servlet context
Reference bean in application context from servlet context [message #659389] Sun, 13 March 2011 09:46 Go to next message
Eva Troels is currently offline Eva Troels
Messages: 17
Registered: December 2010
Junior Member
Hi

Basically i have a web.xml with roughly the same structure as the greenpages demo app:

...
	<context-param>
		<param-name>contextClass</param-name>
		<param-value>org.eclipse.virgo.web.dm.ServerOsgiBundleXmlWebApplicationContext</param-value>
	</context-param>

	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
	<servlet>
		<servlet-name>novonet</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
	</servlet>


 	<servlet-mapping>
		<servlet-name>novonet</servlet-name>
		<url-pattern>*.do</url-pattern>
	</servlet-mapping> 



I have my applicationContext.xml where i use the osgi namespace to identify a list of services:

	<osgi:list id="messageSourceList" cardinality="0..N" interface="org.springframework.context.MessageSource" context-class-loader="service-provider" filter="(name=portal)" />


and then my novonet-servlet.xml where I try to use this bean:
	<bean name="messageSource" class="com.ibm.healthconnect.modules.HealthConnectMessageSource">
		<property name="messageSources" ref="messageSourceList" />
	</bean>


but when running the application i get the following (as if the servlet context cannot see the application context) - what is going on?

[2011-03-13 14:35:24.937] start-signalling-1 org.springframework.web.servlet.DispatcherServlet Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageSource' defined in ServletContext resource [/WEB-INF/novonet-servlet.xml]: Cannot resolve reference to bean 'messageSourceList' while setting bean property 'messageSources'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionExcept ion: No bean named 'messageSourceList' is defined
at org.springframework.beans.factory.support.BeanDefinitionValu eResolver.resolveReference(BeanDefinitionValueResolver.java: 328)
at org.springframework.beans.factory.support.BeanDefinitionValu eResolver.resolveValueIfNecessary(BeanDefinitionValueResolve r.java:106)
at org.springframework.beans.factory.support.AbstractAutowireCa pableBeanFactory.applyPropertyValues(AbstractAutowireCapable BeanFactory.java:1325)
at org.springframework.beans.factory.support.AbstractAutowireCa pableBeanFactory.populateBean(AbstractAutowireCapableBeanFac tory.java:1086)
at org.springframework.beans.factory.support.AbstractAutowireCa pableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFac tory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCa pableBeanFactory.createBean(AbstractAutowireCapableBeanFacto ry.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactor y$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBe anRegistry.getSingleton(DefaultSingletonBeanRegistry.java:22 2)
at org.springframework.beans.factory.support.AbstractBeanFactor y.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactor y.getBean(AbstractBeanFactory.java:194)
at org.springframework.context.support.AbstractApplicationConte xt.initMessageSource(AbstractApplicationContext.java:755)
at org.springframework.context.support.AbstractApplicationConte xt.refresh(AbstractApplicationContext.java:413)
at org.springframework.web.servlet.FrameworkServlet.createWebAp plicationContext(FrameworkServlet.java:442)
at org.springframework.web.servlet.FrameworkServlet.createWebAp plicationContext(FrameworkServlet.java:458)
at org.springframework.web.servlet.FrameworkServlet.initWebAppl icationContext(FrameworkServlet.java:339)
at org.springframework.web.servlet.FrameworkServlet.initServlet Bean(FrameworkServlet.java:306)
at org.springframework.web.servlet.HttpServletBean.init(HttpSer vletBean.java:127)
at javax.servlet.GenericServlet.init(GenericServlet.java:212)
at org.eclipse.virgo.snaps.core.internal.webapp.container.Servl etManager$1.doWithClassLoader(ServletManager.java:71)
at org.eclipse.virgo.snaps.core.internal.webapp.container.Servl etManager$1.doWithClassLoader(ServletManager.java:1)
at org.eclipse.virgo.snaps.core.internal.webapp.container.Manag erUtils.doWithThreadContextClassLoader(ManagerUtils.java:36)
at org.eclipse.virgo.snaps.core.internal.webapp.container.Servl etManager.init(ServletManager.java:65)
at org.eclipse.virgo.snaps.core.internal.webapp.container.Stand ardVirtualContainer.init(StandardVirtualContainer.java:85)
at org.eclipse.virgo.snaps.core.internal.webapp.WebAppSnap.init (WebAppSnap.java:106)
at org.eclipse.virgo.snaps.core.internal.SnapFactoryMonitor$Sna pBinder.hostPublished(SnapFactoryMonitor.java:166)
at org.eclipse.virgo.snaps.core.internal.SnapFactoryMonitor$Sna pBinder.serviceChanged(SnapFactoryMonitor.java:230)
at org.eclipse.osgi.internal.serviceregistry.FilteredServiceLis tener.serviceChanged(FilteredServiceListener.java:104)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.d ispatchEvent(BundleContextImpl.java:933)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEve nt(EventManager.java:227)
at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEv entSynchronous(ListenerQueue.java:149)
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.pu blishServiceEventPrivileged(ServiceRegistry.java:756)
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.pu blishServiceEvent(ServiceRegistry.java:711)
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistratio nImpl.register(ServiceRegistrationImpl.java:130)
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.re gisterService(ServiceRegistry.java:206)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.r egisterService(BundleContextImpl.java:507)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.r egisterService(BundleContextImpl.java:525)
at org.eclipse.gemini.web.internal.StandardWebApplication.publi shServletContext(StandardWebApplication.java:141)
at org.eclipse.gemini.web.internal.StandardWebApplication.start (StandardWebApplication.java:91)
at org.eclipse.virgo.web.core.internal.WebBundleLifecycleListen er.onStarted(WebBundleLifecycleListener.java:120)
at org.eclipse.virgo.kernel.install.artifact.internal.ArtifactS tateMonitor.onStarted(ArtifactStateMonitor.java:205)
at org.eclipse.virgo.kernel.install.artifact.internal.AbstractI nstallArtifact.asyncStartSucceeded(AbstractInstallArtifact.j ava:273)
at org.eclipse.virgo.kernel.install.artifact.internal.AbstractI nstallArtifact.access$0(AbstractInstallArtifact.java:270)
at org.eclipse.virgo.kernel.install.artifact.internal.AbstractI nstallArtifact$StateMonitorSignal.signalSuccessfulCompletion (AbstractInstallArtifact.java:223)
at org.eclipse.virgo.kernel.core.internal.BundleStartTracker$1. run(BundleStartTracker.java:140)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Threa dPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoo lExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionExcept ion: No bean named 'messageSourceList' is defined
at org.springframework.beans.factory.support.DefaultListableBea nFactory.getBeanDefinition(DefaultListableBeanFactory.java:5 27)
at org.springframework.beans.factory.support.AbstractBeanFactor y.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1083 )
at org.springframework.beans.factory.support.AbstractBeanFactor y.doGetBean(AbstractBeanFactory.java:274)
at org.springframework.beans.factory.support.AbstractBeanFactor y.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.AbstractBeanFactor y.doGetBean(AbstractBeanFactory.java:266)
at org.springframework.beans.factory.support.AbstractBeanFactor y.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.BeanDefinitionValu eResolver.resolveReference(BeanDefinitionValueResolver.java: 322)
... 46 common frames omitted
Re: Reference bean in application context from servlet context [message #659401 is a reply to message #659389] Sun, 13 March 2011 12:11 Go to previous messageGo to next message
Eva Troels is currently offline Eva Troels
Messages: 17
Registered: December 2010
Junior Member
Hmm...could be due to the fact that I'm using Snaps.
I found http://dev.eclipse.org/mhonarc/lists/virgo-dev/msg00366.html and this seems to indicate this.

/Eva
Re: Reference bean in application context from servlet context [message #659405 is a reply to message #659401] Sun, 13 March 2011 12:30 Go to previous message
Dmitry Sklyut is currently offline Dmitry Sklyut
Messages: 268
Registered: January 2010
Senior Member
Snaps is the reason you are seeing this.

With snaps you should only use DispatcherServlet app-context not the root.webapp context (the one listener sets up).

Because you are attaching to the context or the host web application, there needs to be some level of scoping done on the servlet context attributes.

Previous Topic:how to trouble shoot class not found issue
Next Topic:Eclipse debug hangs when manually stoping bundle from console
Goto Forum:
  


Current Time: Thu Apr 24 02:04:21 EDT 2014

Powered by FUDForum. Page generated in 0.01594 seconds