You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by Charles Moulliard <cm...@gmail.com> on 2011/02/01 08:58:59 UTC

Spring DM - OSGI service register and use in the same bundle

Hi,

I try to register an OSGI Service and use it in the same bundle but
get an unsatisfied dependencies error.

Is it allow to do that ?

Error :

08:54:40,317 | INFO  | ExtenderThread-2 | DependencyServiceManager
    | startup.DependencyServiceManager  288 | 76 -
org.springframework.osgi.extender - 1.2.0 | Adding OSGi service
dependency for importer
[&org.springframework.osgi.service.importer.support.OsgiServiceProxyFactoryBean#0]
matching OSGi filter
[(&(objectClass=org.springframework.transaction.PlatformTransactionManager)(tx=JPA))]
08:54:40,318 | INFO  | ExtenderThread-2 | DependencyServiceManager
    | startup.DependencyServiceManager  232 | 76 -
org.springframework.osgi.extender - 1.2.0 |
OsgiBundleXmlApplicationContext(bundle=com.goodyear.emea.gicl.esb.sap-all,
config=osgibundle:/META-INF/spring/*.xml) is waiting for unsatisfied
dependencies [[&org.springframework.osgi.service.importer.support.OsgiServiceProxyFactoryBean#0]]

Config

        aaa.xml file

	<!-- TransactionManager is required -->
	<bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
		<property name="entityManagerFactory" ref="entityManagerFactory" />
		<property name="dataSource" ref="dataSource" />
	</bean>
	
	<!--  Expose Transaction Manager -->
	<osgi:service ref="txManager"
interface="org.springframework.transaction.PlatformTransactionManager">
            <service-properties>
                <entry key="tx" value="JPA"/>
            </service-properties>
        </osgi:service>


    bbb.xml file

	<bean id="PROPAGATION_REQUIRES_NEW"
class="org.apache.camel.spring.spi.SpringTransactionPolicy">
        <property name="transactionManager">
	       <osgi:reference filter="(tx=JPA)"
interface="org.springframework.transaction.PlatformTransactionManager"/>
        </property>
  		<property name="propagationBehaviorName" value="PROPAGATION_REQUIRES_NEW"/>
	</bean>

Regards,

Charles Moulliard

Sr. Principal Solution Architect - FuseSource
Apache Committer

Blog : http://cmoulliard.blogspot.com
Twitter : http://twitter.com/cmoulliard
Linkedin : http://www.linkedin.com/in/charlesmoulliard
Skype: cmoulliard

Re: Spring DM - OSGI service register and use in the same bundle

Posted by Charles Moulliard <cm...@gmail.com>.
I try to do that because I have issue with Hibernate + JPA + Spring Tx
regarding to transaction commit who does not occur when using separate
bundles. This is why I created one bundle to see if the same error
occurs or not. By the way, If I refer directly to the bean instead of
the osgi:reference, everything works fine


On Tue, Feb 1, 2011 at 9:11 AM, Andreas Pieber <an...@gmail.com> wrote:
> TBH I've never took a look into springs source to know y, but it doesn't like it
> if you import in the same bundle you export it. Simple solution is to split into
> to different bundles (as jb suggested), or use the bean txManager directly
> instead of the service.
>
> BTW, it doesn't matter if you define you beans in one or 10 .xml files in one
> bundle. Spring "concats" them first and start to load them afterwards.
>
> kind regards,
> andreas
>
> On Tue, Feb 01, 2011 at 08:58:59AM +0100, Charles Moulliard wrote:
>> Hi,
>>
>> I try to register an OSGI Service and use it in the same bundle but
>> get an unsatisfied dependencies error.
>>
>> Is it allow to do that ?
>>
>> Error :
>>
>> 08:54:40,317 | INFO  | ExtenderThread-2 | DependencyServiceManager
>>     | startup.DependencyServiceManager  288 | 76 -
>> org.springframework.osgi.extender - 1.2.0 | Adding OSGi service
>> dependency for importer
>> [&org.springframework.osgi.service.importer.support.OsgiServiceProxyFactoryBean#0]
>> matching OSGi filter
>> [(&(objectClass=org.springframework.transaction.PlatformTransactionManager)(tx=JPA))]
>> 08:54:40,318 | INFO  | ExtenderThread-2 | DependencyServiceManager
>>     | startup.DependencyServiceManager  232 | 76 -
>> org.springframework.osgi.extender - 1.2.0 |
>> OsgiBundleXmlApplicationContext(bundle=com.goodyear.emea.gicl.esb.sap-all,
>> config=osgibundle:/META-INF/spring/*.xml) is waiting for unsatisfied
>> dependencies [[&org.springframework.osgi.service.importer.support.OsgiServiceProxyFactoryBean#0]]
>>
>> Config
>>
>>         aaa.xml file
>>
>>       <!-- TransactionManager is required -->
>>       <bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
>>               <property name="entityManagerFactory" ref="entityManagerFactory" />
>>               <property name="dataSource" ref="dataSource" />
>>       </bean>
>>
>>       <!--  Expose Transaction Manager -->
>>       <osgi:service ref="txManager"
>> interface="org.springframework.transaction.PlatformTransactionManager">
>>             <service-properties>
>>                 <entry key="tx" value="JPA"/>
>>             </service-properties>
>>         </osgi:service>
>>
>>
>>     bbb.xml file
>>
>>       <bean id="PROPAGATION_REQUIRES_NEW"
>> class="org.apache.camel.spring.spi.SpringTransactionPolicy">
>>         <property name="transactionManager">
>>              <osgi:reference filter="(tx=JPA)"
>> interface="org.springframework.transaction.PlatformTransactionManager"/>
>>         </property>
>>               <property name="propagationBehaviorName" value="PROPAGATION_REQUIRES_NEW"/>
>>       </bean>
>>
>> Regards,
>>
>> Charles Moulliard
>>
>> Sr. Principal Solution Architect - FuseSource
>> Apache Committer
>>
>> Blog : http://cmoulliard.blogspot.com
>> Twitter : http://twitter.com/cmoulliard
>> Linkedin : http://www.linkedin.com/in/charlesmoulliard
>> Skype: cmoulliard
>

Re: Spring DM - OSGI service register and use in the same bundle

Posted by Andreas Pieber <an...@gmail.com>.
TBH I've never took a look into springs source to know y, but it doesn't like it
if you import in the same bundle you export it. Simple solution is to split into
to different bundles (as jb suggested), or use the bean txManager directly
instead of the service. 

BTW, it doesn't matter if you define you beans in one or 10 .xml files in one
bundle. Spring "concats" them first and start to load them afterwards.

kind regards,
andreas

On Tue, Feb 01, 2011 at 08:58:59AM +0100, Charles Moulliard wrote:
> Hi,
> 
> I try to register an OSGI Service and use it in the same bundle but
> get an unsatisfied dependencies error.
> 
> Is it allow to do that ?
> 
> Error :
> 
> 08:54:40,317 | INFO  | ExtenderThread-2 | DependencyServiceManager
>     | startup.DependencyServiceManager  288 | 76 -
> org.springframework.osgi.extender - 1.2.0 | Adding OSGi service
> dependency for importer
> [&org.springframework.osgi.service.importer.support.OsgiServiceProxyFactoryBean#0]
> matching OSGi filter
> [(&(objectClass=org.springframework.transaction.PlatformTransactionManager)(tx=JPA))]
> 08:54:40,318 | INFO  | ExtenderThread-2 | DependencyServiceManager
>     | startup.DependencyServiceManager  232 | 76 -
> org.springframework.osgi.extender - 1.2.0 |
> OsgiBundleXmlApplicationContext(bundle=com.goodyear.emea.gicl.esb.sap-all,
> config=osgibundle:/META-INF/spring/*.xml) is waiting for unsatisfied
> dependencies [[&org.springframework.osgi.service.importer.support.OsgiServiceProxyFactoryBean#0]]
> 
> Config
> 
>         aaa.xml file
> 
> 	<!-- TransactionManager is required -->
> 	<bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
> 		<property name="entityManagerFactory" ref="entityManagerFactory" />
> 		<property name="dataSource" ref="dataSource" />
> 	</bean>
> 	
> 	<!--  Expose Transaction Manager -->
> 	<osgi:service ref="txManager"
> interface="org.springframework.transaction.PlatformTransactionManager">
>             <service-properties>
>                 <entry key="tx" value="JPA"/>
>             </service-properties>
>         </osgi:service>
> 
> 
>     bbb.xml file
> 
> 	<bean id="PROPAGATION_REQUIRES_NEW"
> class="org.apache.camel.spring.spi.SpringTransactionPolicy">
>         <property name="transactionManager">
> 	       <osgi:reference filter="(tx=JPA)"
> interface="org.springframework.transaction.PlatformTransactionManager"/>
>         </property>
>   		<property name="propagationBehaviorName" value="PROPAGATION_REQUIRES_NEW"/>
> 	</bean>
> 
> Regards,
> 
> Charles Moulliard
> 
> Sr. Principal Solution Architect - FuseSource
> Apache Committer
> 
> Blog : http://cmoulliard.blogspot.com
> Twitter : http://twitter.com/cmoulliard
> Linkedin : http://www.linkedin.com/in/charlesmoulliard
> Skype: cmoulliard

Re: Spring DM - OSGI service register and use in the same bundle

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Hi Charles,

You should split into two different bundles. I think that the interface 
is not yet bound when the reference tries to resolve it.

To be honest, I've never tried to use a service reference to another 
descriptor file in the same bundle (I defined all in the same blueprint 
descriptor, so no need to use a service reference internally).

Regards
JB

On 02/01/2011 08:58 AM, Charles Moulliard wrote:
> Hi,
>
> I try to register an OSGI Service and use it in the same bundle but
> get an unsatisfied dependencies error.
>
> Is it allow to do that ?
>
> Error :
>
> 08:54:40,317 | INFO  | ExtenderThread-2 | DependencyServiceManager
>      | startup.DependencyServiceManager  288 | 76 -
> org.springframework.osgi.extender - 1.2.0 | Adding OSGi service
> dependency for importer
> [&org.springframework.osgi.service.importer.support.OsgiServiceProxyFactoryBean#0]
> matching OSGi filter
> [(&(objectClass=org.springframework.transaction.PlatformTransactionManager)(tx=JPA))]
> 08:54:40,318 | INFO  | ExtenderThread-2 | DependencyServiceManager
>      | startup.DependencyServiceManager  232 | 76 -
> org.springframework.osgi.extender - 1.2.0 |
> OsgiBundleXmlApplicationContext(bundle=com.goodyear.emea.gicl.esb.sap-all,
> config=osgibundle:/META-INF/spring/*.xml) is waiting for unsatisfied
> dependencies [[&org.springframework.osgi.service.importer.support.OsgiServiceProxyFactoryBean#0]]
>
> Config
>
>          aaa.xml file
>
> 	<!-- TransactionManager is required -->
> 	<bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
> 		<property name="entityManagerFactory" ref="entityManagerFactory" />
> 		<property name="dataSource" ref="dataSource" />
> 	</bean>
> 	
> 	<!--  Expose Transaction Manager -->
> 	<osgi:service ref="txManager"
> interface="org.springframework.transaction.PlatformTransactionManager">
>              <service-properties>
>                  <entry key="tx" value="JPA"/>
>              </service-properties>
>          </osgi:service>
>
>
>      bbb.xml file
>
> 	<bean id="PROPAGATION_REQUIRES_NEW"
> class="org.apache.camel.spring.spi.SpringTransactionPolicy">
>          <property name="transactionManager">
> 	<osgi:reference filter="(tx=JPA)"
> interface="org.springframework.transaction.PlatformTransactionManager"/>
>          </property>
>    		<property name="propagationBehaviorName" value="PROPAGATION_REQUIRES_NEW"/>
> 	</bean>
>
> Regards,
>
> Charles Moulliard
>
> Sr. Principal Solution Architect - FuseSource
> Apache Committer
>
> Blog : http://cmoulliard.blogspot.com
> Twitter : http://twitter.com/cmoulliard
> Linkedin : http://www.linkedin.com/in/charlesmoulliard
> Skype: cmoulliard

Re: Spring DM - OSGI service register and use in the same bundle

Posted by Guillaume Nodet <gn...@gmail.com>.
Spring-DM and blueprint do not support well such a construct unless
the referenced service is an optional dependency.
The reason is that dependencies must be satisfied before the
application is started, so it waits forever.
You need to either use an optional dependency or directly reference the bean

       <bean id="PROPAGATION_REQUIRES_NEW"
class="org.apache.camel.spring.spi.SpringTransactionPolicy">
               <property name="transactionManager" ref="txManager"/>
               <property name="propagationBehaviorName"
value="PROPAGATION_REQUIRES_NEW"/>
       </bean>

On Tue, Feb 1, 2011 at 08:58, Charles Moulliard <cm...@gmail.com> wrote:
> Hi,
>
> I try to register an OSGI Service and use it in the same bundle but
> get an unsatisfied dependencies error.
>
> Is it allow to do that ?
>
> Error :
>
> 08:54:40,317 | INFO  | ExtenderThread-2 | DependencyServiceManager
>    | startup.DependencyServiceManager  288 | 76 -
> org.springframework.osgi.extender - 1.2.0 | Adding OSGi service
> dependency for importer
> [&org.springframework.osgi.service.importer.support.OsgiServiceProxyFactoryBean#0]
> matching OSGi filter
> [(&(objectClass=org.springframework.transaction.PlatformTransactionManager)(tx=JPA))]
> 08:54:40,318 | INFO  | ExtenderThread-2 | DependencyServiceManager
>    | startup.DependencyServiceManager  232 | 76 -
> org.springframework.osgi.extender - 1.2.0 |
> OsgiBundleXmlApplicationContext(bundle=com.goodyear.emea.gicl.esb.sap-all,
> config=osgibundle:/META-INF/spring/*.xml) is waiting for unsatisfied
> dependencies [[&org.springframework.osgi.service.importer.support.OsgiServiceProxyFactoryBean#0]]
>
> Config
>
>        aaa.xml file
>
>        <!-- TransactionManager is required -->
>        <bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
>                <property name="entityManagerFactory" ref="entityManagerFactory" />
>                <property name="dataSource" ref="dataSource" />
>        </bean>
>
>        <!--  Expose Transaction Manager -->
>        <osgi:service ref="txManager"
> interface="org.springframework.transaction.PlatformTransactionManager">
>            <service-properties>
>                <entry key="tx" value="JPA"/>
>            </service-properties>
>        </osgi:service>
>
>
>    bbb.xml file
>
>        <bean id="PROPAGATION_REQUIRES_NEW"
> class="org.apache.camel.spring.spi.SpringTransactionPolicy">
>        <property name="transactionManager">
>               <osgi:reference filter="(tx=JPA)"
> interface="org.springframework.transaction.PlatformTransactionManager"/>
>        </property>
>                <property name="propagationBehaviorName" value="PROPAGATION_REQUIRES_NEW"/>
>        </bean>
>
> Regards,
>
> Charles Moulliard
>
> Sr. Principal Solution Architect - FuseSource
> Apache Committer
>
> Blog : http://cmoulliard.blogspot.com
> Twitter : http://twitter.com/cmoulliard
> Linkedin : http://www.linkedin.com/in/charlesmoulliard
> Skype: cmoulliard
>



-- 
Cheers,
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/
------------------------
Open Source SOA
http://fusesource.com