Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi everybody,
I have declared a datasource in Karaf using a blueprint file.
The file looks like that :
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/care4drupal"/>
<property name="username" value="xxx" />
<property name="password" value="xxx" />
<property name="initialSize" value="5" />
<property name="maxIdle" value="10"/>
<property name="minIdle" value="10" />
<property name="maxActive" value="25"/>
<property name="maxWait" value="-1"/>
<property name="validationQuery" value="select 1"/>
<property name="testOnBorrow" value="false"/>
<property name="testWhileIdle" value="true"/>
<property name="timeBetweenEvictionRunsMillis" value="120000"/>
<property name="minEvictableIdleTimeMillis" value="180000"/>
<property name="numTestsPerEvictionRun" value="2"/>
<property name="defaultAutoCommit" value="false"/>
</bean>
<service interface="javax.sql.DataSource" ref="dataSource">
<service-properties>
<entry key="osgi.jndi.service.name" value="jdbc/mysqlSimulateur"/>
</service-properties>
</service>
</blueprint>
My question is very simple : how can access this DataSource in pur java code (inside a routines or a tJava component) ?
I have tried something like that :
Context ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup("osgi:service/javax.sqlDataSource/(name=jdbc/mysqlSimulateur)");
and
Context ctx = new InitialContext();
DataSource ds2 = (DataSource) ctx.lookup("osgi:service/jdbc/mysqlSimulateur");
but it doesn't work !
Any idea ?
Best regards.