Reputation: 25
Using a blueprint.xml, I am trying to create a jndi service for datasource and having a reference in the same bundle.The datasource service is not activated and the reference fails after certain time and results in time out. Also, when the reference of service is commented in the blueprint, the service gets activated. Is there a way I can handle the activation of the service with its reference also present in the same bundle.
<service id="zDS" interface="javax.sql.DataSource" ref="zOltpDataSource">
<service-properties>
<entry key="osgi.jndi.service.name" value="jdbc/zDS"/>
</service-properties>
</service>
<bean id="zDao"
class="com.h.h.common.dao.ZDaoImpl">
<property name="dataSource" ref="dataSource" />
</bean>
<reference id="dataSource" interface="javax.sql.DataSource"
filter="(osgi.jndi.service.name=jdbc/zDS)">
</reference>
<bean id="zOltpDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${z.driverClassName}"/>
<property name="url" value="${z.url}"/>
<property name="username" value="${z.username}"/>
<property name="password" value="${z.password}"/>
<property name="initialSize" value="${z.initialSize}"/>
<property name="maxIdle" value="${z.maxIdle}"/>
<property name="maxActive" value="${z.maxActive}"/>
<property name="validationQuery" value="${z.validationQuery}"/>
<property name="testOnBorrow" value="${z.testOnBorrow}"/>
</bean>
Upvotes: 0
Views: 156
Reputation: 23948
A Blueprint container will not initialise until all of its mandatory dependencies are satisfied: see Initialization of a Blueprint Container from the Blueprint Specification.
Therefore you cannot use a <reference>
to a service that is only published from the same container, because there is effectively a circular dependency. Of course your container will start if there is a matching DataSource
service from another bundle.
You shouldn't need to refer to the service, however. Just inject the zOltpDataSource
bean directly into the zDao
bean as follows:
<bean id="zDao"
class="com.h.h.common.dao.ZDaoImpl">
<property name="dataSource" ref="zOltpDataSource" />
</bean>
Upvotes: 1