Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 402449

Summary: Services cannot be exported by referencing spring bean name aliases
Product: [RT] Gemini.Blueprint Reporter: Jean-Pierre Bergamin <james>
Component: CoreAssignee: Project Inbox <gemini.blueprint-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: enhancement    
Priority: P3 CC: glyn.normington, olaf
Version: 1.0.2.RELEASEFlags: glyn.normington: documentation+
Target Milestone: 2.1.0.M01   
Hardware: All   
OS: All   
Whiteboard:
Bug Depends on:    
Bug Blocks: 393961    

Description Jean-Pierre Bergamin CLA 2013-03-05 11:00:18 EST
Assume having a spring bean with an alias like:
<bean id="myBean" name="myAlias" class="MyClass" />

Exporting the bean with its id works:
<service ref="myBean" interface="MyInterface" />

Whereas exporting it with the alias does not work:
<service ref="myAlias" interface="MyInterface" />

The stacktrace is (with "myTransactionManager" as an alias of the bean with id "transactionManager"):

[2013-03-05 16:53:38.628] start-signalling-2           <DE0006E> Start failed for bundle 'validation-test' version '0.0.1.BUILD-SNAPSHOT'. org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.eclipse.gemini.blueprint.service.exporter.support.OsgiServiceFactoryBean#0': Invocation of init method failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'myTransactionManager' is defined
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1486)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:524)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:608)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
	at org.eclipse.gemini.blueprint.context.support.AbstractDelegatedExecutionApplicationContext.access$1600(AbstractDelegatedExecutionApplicationContext.java:60)
	at org.eclipse.gemini.blueprint.context.support.AbstractDelegatedExecutionApplicationContext$4.run(AbstractDelegatedExecutionApplicationContext.java:325)
	at org.eclipse.gemini.blueprint.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)
	at org.eclipse.gemini.blueprint.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplicationContext.java:290)
	at org.eclipse.gemini.blueprint.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(DependencyWaiterApplicationContextExecutor.java:137)
	at org.eclipse.virgo.kernel.agent.dm.ContextPropagatingTaskExecutor$2.run(ContextPropagatingTaskExecutor.java:95)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
	at java.lang.Thread.run(Thread.java:722)
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'myTransactionManager' is defined
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:568)
	at org.eclipse.gemini.blueprint.service.exporter.support.OsgiServiceFactoryBean.afterPropertiesSet(OsgiServiceFactoryBean.java:196)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1545)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1483)
	... 17 common frames omitted


This worked in Virgo 3.0.x.

The sample app at https://bitbucket.org/ractive/validation-test has been updated to show this behavior.
Comment 1 Glyn Normington CLA 2013-03-06 06:25:18 EST
Presumably this is due to a change in behaviour between Spring DM 1.2.x in Virgo 3.0.x and Gemini Blueprint, which is based on Spring DM 2.0, in Virgo 3.5.x.
Comment 2 Glyn Normington CLA 2013-03-08 04:17:30 EST
This is working as designed since Gemini Blueprint requires the service element ref attribute to refer to the id of a bean element rather than the value of the bean element's name attribute. This is consistent with the OSGi Blueprint specification which does not support a name attribute on a bean element.

Let's use this bug, therefore, to clarify the documentation.
Comment 3 Olaf Otto CLA 2017-02-03 06:21:15 EST
Assigned to upcoming milestone
Comment 4 Olaf Otto CLA 2017-03-24 11:05:31 EDT
As commented, works compliant to the specification: Aliases are not used to reference services, using IDs is required
Comment 5 Olaf Otto CLA 2017-05-09 09:41:35 EDT
Released - closing.