You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomee.apache.org by Bob_13042013 <sh...@yahoo.com> on 2013/04/13 13:08:53 UTC

cannot JNDI datasource with initialcontext lookup

Hi,

I recently moved from Oracle Weblogic to TomEE. It was all great until I ran
into the datasource configuration problem. I tried the following:

First the postgres jdbc driver was dropped in the TomEE/lib directory. Then
the following combinations were tried:

a.) resource configuration in tomee.xml.
<Resource id="myDatasource" type="DataSource">
    JdbcDriver   org.postgresql.Driver
    JdbcUrl  jdbc:postgresql://localhost:5432/test
    UserName     user
    Password     pass
</Resource>

b.) resource configuration in server.xml. The Resource element was put under
GlobalNamingResources.

c.) creating resource configuration in the META-INF/context.xml of the web
app. Adding to web.xml the following code:
<resource-ref>
   <res-ref-name>myDatasource</res-ref-name>
   <res-type>javax.sql.DataSource</res-type>
</resource-ref>

Whichever configuration aforementioned was used the web app could not locate
the datasource with the JNDI. I used in the initial context lookup also the
recommended prefix "java:comp/env/" not much help.

In Weblogic it is very simple. You create the datasource in the weblogic
Admin. Inside the web app you call the JNDI and no issues at all. No prefix
needs to be put to find the datasource, only the datasource name configured
inside Weblogic.

Do you know what could be the issue ?

Thanks.





--
View this message in context: http://openejb.979440.n4.nabble.com/cannot-JNDI-datasource-with-initialcontext-lookup-tp4662211.html
Sent from the OpenEJB Dev mailing list archive at Nabble.com.

Re: cannot JNDI datasource with initialcontext lookup

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi

basically you just need a <Resource id="X" /> lock in tomee.xml then lookup
the resource through java:openejb/Resource/X

if it doesn't work just provide us a sample showing it doesn't work please

*Romain Manni-Bucau*
*Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
*Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/>
*LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
*Github: https://github.com/rmannibucau*



2013/4/14 Bob_13042013 <sh...@yahoo.com>

> When Context is mentioned in the docs is this the <TOMEE>/conf/context.xml
> or
> it is one specific to the web app ?
>
> I have the feeling Postgres does cannot be configured as a shared resource
> in TomEE.
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/cannot-JNDI-datasource-with-initialcontext-lookup-tp4662211p4662246.html
> Sent from the OpenEJB Dev mailing list archive at Nabble.com.
>

Re: cannot JNDI datasource with initialcontext lookup

Posted by Bob_13042013 <sh...@yahoo.com>.
When Context is mentioned in the docs is this the <TOMEE>/conf/context.xml or
it is one specific to the web app ?

I have the feeling Postgres does cannot be configured as a shared resource
in TomEE.



--
View this message in context: http://openejb.979440.n4.nabble.com/cannot-JNDI-datasource-with-initialcontext-lookup-tp4662211p4662246.html
Sent from the OpenEJB Dev mailing list archive at Nabble.com.

Re: cannot JNDI datasource with initialcontext lookup

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Tomee.xml

Check datasources through jmx
Le 14 avr. 2013 13:03, "Bob_13042013" <sh...@yahoo.com> a écrit :

> You said I should use in the JNDI lookup for java:/openejb/Resource. Does
> it
> mean openejb.xml should be configured instead of tomee.xml ?
>
> Where is openejb.xml located ?
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/cannot-JNDI-datasource-with-initialcontext-lookup-tp4662211p4662226.html
> Sent from the OpenEJB Dev mailing list archive at Nabble.com.
>

Re: cannot JNDI datasource with initialcontext lookup

Posted by Bob_13042013 <sh...@yahoo.com>.
You said I should use in the JNDI lookup for java:/openejb/Resource. Does it
mean openejb.xml should be configured instead of tomee.xml ?

Where is openejb.xml located ?



--
View this message in context: http://openejb.979440.n4.nabble.com/cannot-JNDI-datasource-with-initialcontext-lookup-tp4662211p4662226.html
Sent from the OpenEJB Dev mailing list archive at Nabble.com.

Re: cannot JNDI datasource with initialcontext lookup

Posted by Bob_13042013 <sh...@yahoo.com>.
How would you verify if the Datasource has been correctly configured on TomEE
and if the ping to the DB works ?



--
View this message in context: http://openejb.979440.n4.nabble.com/cannot-JNDI-datasource-with-initialcontext-lookup-tp4662211p4662225.html
Sent from the OpenEJB Dev mailing list archive at Nabble.com.

Re: cannot JNDI datasource with initialcontext lookup

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Synchronizing it works fine
Le 14 avr. 2013 08:57, "Bob_13042013" <sh...@yahoo.com> a écrit :

> Initially tomee.xml was in the TomEE installation directory. Afterwards I
> tried copying it to the Servers project in the config of Tomcat7. I also
> used the Publish feature to synchronize the tomee.xml with the tomcat
> instance.
>
>
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/cannot-JNDI-datasource-with-initialcontext-lookup-tp4662211p4662219.html
> Sent from the OpenEJB Dev mailing list archive at Nabble.com.
>

Re: cannot JNDI datasource with initialcontext lookup

Posted by Bob_13042013 <sh...@yahoo.com>.
Initially tomee.xml was in the TomEE installation directory. Afterwards I
tried copying it to the Servers project in the config of Tomcat7. I also
used the Publish feature to synchronize the tomee.xml with the tomcat
instance.





--
View this message in context: http://openejb.979440.n4.nabble.com/cannot-JNDI-datasource-with-initialcontext-lookup-tp4662211p4662219.html
Sent from the OpenEJB Dev mailing list archive at Nabble.com.

Re: cannot JNDI datasource with initialcontext lookup

Posted by Romain Manni-Bucau <rm...@gmail.com>.
And eclipse? Hmm where is your tomee.xml? In your tomcat7 servers config
(wtp)?
Le 13 avr. 2013 21:42, "Bob_13042013" <sh...@yahoo.com> a écrit :

> Hi,
>
> Thx for your suggestions, I truly appreciate them.
>
> Tried using the lookup in java:openejb/Resource, no success.
>
> Tried 1) + @Resource(name="id"), no success either.
>
> Tried using java:global, nothing.
>
> When I run the server I see in the Console datasource being configured. Is
> there a way to verify if the Datasource is configured and works properly in
> TomEE ?
>
> I tried also removing and adding the Tomcat server and setting Server
> locations to Use Tomcat installation. No luck either.
>
> Also tried copying tomee.xml to Servers workspace, when workspace metadata
> was used, did not help.
>
> The most interesting would be to know how to properly configure Eclipse and
> TomEE  (tomee.xml) in order to be able to get the PostGres datasource by
> JNDI. If not possible by JNDI then any other means. If you follow the
> documentation you do not seem to get the desired result. Cannot believe it
> takes so much trouble to configure one datasource.
>
> Maybe it would be better to use JBoss instead ?
>
>
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/cannot-JNDI-datasource-with-initialcontext-lookup-tp4662211p4662217.html
> Sent from the OpenEJB Dev mailing list archive at Nabble.com.
>

Re: cannot JNDI datasource with initialcontext lookup

Posted by Bob_13042013 <sh...@yahoo.com>.
Hi,

Thx for your suggestions, I truly appreciate them.

Tried using the lookup in java:openejb/Resource, no success. 

Tried 1) + @Resource(name="id"), no success either.

Tried using java:global, nothing.

When I run the server I see in the Console datasource being configured. Is
there a way to verify if the Datasource is configured and works properly in
TomEE ?

I tried also removing and adding the Tomcat server and setting Server
locations to Use Tomcat installation. No luck either.

Also tried copying tomee.xml to Servers workspace, when workspace metadata
was used, did not help.

The most interesting would be to know how to properly configure Eclipse and
TomEE  (tomee.xml) in order to be able to get the PostGres datasource by
JNDI. If not possible by JNDI then any other means. If you follow the
documentation you do not seem to get the desired result. Cannot believe it
takes so much trouble to configure one datasource.

Maybe it would be better to use JBoss instead ?





--
View this message in context: http://openejb.979440.n4.nabble.com/cannot-JNDI-datasource-with-initialcontext-lookup-tp4662211p4662217.html
Sent from the OpenEJB Dev mailing list archive at Nabble.com.

Re: cannot JNDI datasource with initialcontext lookup

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi a) works but need to lookup in java:openejb/Resource. C should work on
the snapshot.

Finally using 1) + @Resource(name="id")  is the more portable solution IMO
(using java:global can be another option too)
Le 13 avr. 2013 14:00, "Bob_13042013" <sh...@yahoo.com> a écrit :

> Hi,
>
> I recently moved from Oracle Weblogic to TomEE. It was all great until I
> ran
> into the datasource configuration problem. I tried the following:
>
> First the postgres jdbc driver was dropped in the TomEE/lib directory. Then
> the following combinations were tried:
>
> a.) resource configuration in tomee.xml.
> <Resource id="myDatasource" type="DataSource">
>     JdbcDriver   org.postgresql.Driver
>     JdbcUrl  jdbc:postgresql://localhost:5432/test
>     UserName     user
>     Password     pass
> </Resource>
>
> b.) resource configuration in server.xml. The Resource element was put
> under
> GlobalNamingResources.
>
> c.) creating resource configuration in the META-INF/context.xml of the web
> app. Adding to web.xml the following code:
> <resource-ref>
>    <res-ref-name>myDatasource</res-ref-name>
>    <res-type>javax.sql.DataSource</res-type>
> </resource-ref>
>
> Whichever configuration aforementioned was used the web app could not
> locate
> the datasource with the JNDI. I used in the initial context lookup also the
> recommended prefix "java:comp/env/" not much help.
>
> In Weblogic it is very simple. You create the datasource in the weblogic
> Admin. Inside the web app you call the JNDI and no issues at all. No prefix
> needs to be put to find the datasource, only the datasource name configured
> inside Weblogic.
>
> Do you know what could be the issue ?
>
> Thanks.
>
>
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/cannot-JNDI-datasource-with-initialcontext-lookup-tp4662211.html
> Sent from the OpenEJB Dev mailing list archive at Nabble.com.
>