By the way, could you to remove / in the service properties (like this:

<entry key="osgi.jndi.service.name" value="jdbc/person"/>

and see if the lookup works:

ctx.lookup("osgi:service/jdbc/person");

(it's what I fixed this afternoon).

Regards
JB

On 01/17/2014 07:29 PM, schmke wrote:
I have a JDBC DataSource defined with the following datasource.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0";>

     <bean id="dataSource"
class="com.mysql.jdbc.jdbc2.optional.MysqlDataSource">
         <property name="url" value="jdbc:mysql://localhost:3306/person"/>
         <property name="user" value="user"/>
         <property name="password" value="pass"/>
     </bean>

     <service interface="javax.sql.DataSource" ref="dataSource">
         <service-properties>
             <entry key="osgi.jndi.service.name" value="/jdbc/person"/>
         </service-properties>
     </service>
</blueprint>

Executing jdbc:datasources works and shows:

/jdbc/person | MySQL   | 5.6.10  | jdbc:mysql://localhost:3306/person

There is also a JNDI entry returned from jndi:names:

osgi:service/jdbc/person | com.mysql.jdbc.jdbc2.optional.MysqlDataSource

All looks fine, but the following code executed from within my bundle throws
a NameNotFoundException:

         Context ctx = new InitialContext();
         this.dataSource = (DataSource)
ctx.lookup("osgi:service/jdbc/person");

However, I can look it up using the following line of code:

         this.dataSource = (DataSource)
ctx.lookup("osgi:service/javax.sql.DataSource");

Note that I did have to define the JNDI entry with a leading '/' which I saw
another thread about and it sounds like that may be changing.  Is that
causing the problem with the first lookup above and will the fix from the
other thread fix this problem too?



--
View this message in context: 
http://karaf.922171.n3.nabble.com/JNDI-lookup-of-JDBC-DataSource-failing-with-Karaf-3-0-0-tp4031158.html
Sent from the Karaf - User mailing list archive at Nabble.com.


--
Jean-Baptiste Onofré
[email protected]
http://blog.nanthrax.net
Talend - http://www.talend.com

Reply via email to