You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by zsaade <zs...@path-solutions.com> on 2019/02/13 08:39:41 UTC
EAR Datasource javax.naming.NameNoFoundException
Dear All
I have an EAR file that i'm deploying under
<apache-tomee-plume-7.1.0-home>\apps folder, I added the the below
Datasource configuration in the tomee.xml file located under
<tomee-home>\conf:
<?xml version="1.0" encoding="UTF-8"?>
<tomee>
<Deployments dir="apps" />
<Resource id="services" type="javax.sql.DataSource">
jdbcDriver oracle.jdbc.OracleDriver
jdbcUrl jdbc:oracle:thin:@//db-server:1521/ORA11
userName test_server
password test_server
jtaManaged true
defaultAutoCommit true
</Resource>
</tomee>
In my EJB i'm calling the datasource as per the below code:
Context initContext = new InitialContext();
DataSource ds = (DataSource) initContext.lookup("services");
this.ConnectDataSource = ds;
But When i'm starting TomeEE i'm getting the below exception:
javax.naming.NameNoFoundException: Name [services] is not bound in this
Context. Unable to find [services.]
Kindly advice
Best Regards
--
Sent from: http://tomee-openejb.979440.n4.nabble.com/TomEE-Users-f979441.html
Re: EAR Datasource javax.naming.NameNoFoundException
Posted by zsaade <zs...@path-solutions.com>.
Dear jgallimore
Thanks a lot for your detailed example
Just a question the datasource lookup should be as per the below?
Context initContext = new InitialContext();
DataSource ds = (DataSource) initContext.lookup("java:comp/env/services");
this.ConnectDataSource = ds;
And [1] is where the datasource should be available under java:comp/env is
equal to "java:comp/env/services"
Thanks
Best Regard
--
Sent from: http://tomee-openejb.979440.n4.nabble.com/TomEE-Users-f979441.html
Re: EAR Datasource javax.naming.NameNoFoundException
Posted by Jonathan Gallimore <jo...@gmail.com>.
Hi
Your lookup should be:
DataSource datasource = (DataSource)
initContext.lookup("java:comp/env/services");
Can you give that a try?
Cheers
Jon
On Tue, Feb 19, 2019 at 3:15 PM zsaade <zs...@path-solutions.com> wrote:
> Dear jgallimore
>
> Find below <tomee-home>\apps\earFile\jarFile\META-INF\openejb-jar.xml:
> <?xml version="1.0"?>
> <openejb-jar xmlns="http://www.openejb.org/openejb-jar/1.1">
>
> <ejb-deployment ejb-name="TestEJB" deployment-id="TestEJB"
> container-id="Default Stateless Container" >
> <resource-link res-ref-name="services" res-id="Default
> JDBC Database"/>
> </ejb-deployment>
> </openejb-jar>
>
> I changes the the openejb-jar.xml format based on the below links
> specifications:
>
> http://tomee.apache.org/details-on-openejb-jar.html
>
> https://github.com/apache/tomee/blob/master/container/openejb-core/src/main/resources/schema/openejb-jar.xsd
>
> and <tomee-home>\apps\earFile\jarFile\META-INF\ejb-jar.xml:
> <enterprise-beans>
> <session id="Test">
> <description>Describe here the session bean
> Administration</description>
> <display-name>test/testEJB</display-name>
> <ejb-name>TestEJB</ejb-name>
> <home>test.TestHome</home>
> <remote>test.Test</remote>
> <ejb-class>test.TestEJB</ejb-class>
> <session-type>Stateless</session-type>
> <transaction-type>Container</transaction-type>
> <env-entry>
> <env-entry-name>name1</env-entry-name>
> <env-entry-type>java.lang.String</env-entry-type>
> <env-entry-value>value1</env-entry-value>
> </env-entry>
> <resource-ref>
> <res-ref-name>services</res-ref-name>
> <res-type>javax.sql.DataSource</res-type>
> <res-auth>Application</res-auth>
> </resource-ref>
> </session>
> </enterprise-beans>
>
> And <tomee-home>\conf\tomee.xml :
> <?xml version="1.0" encoding="UTF-8"?>
> <tomee>
>
>
>
> <Deployments dir="apps" />
>
> <Resource id="services" type="javax.sql.DataSource">
> ....................
> </Resource>
>
> </tomee>
>
> and in my TestEJB i'm doing the below Connection Call:
>
> DataSource datasource = (DataSource) initContext.lookup("services");
>
> And i'm still getting the below exception:
>
> javax.naming.NameNotFoundException: NAme [services] is nt bound in this
> Context. Unable to find [services].
>
> Best Regards
>
>
>
> --
> Sent from:
> http://tomee-openejb.979440.n4.nabble.com/TomEE-Users-f979441.html
>
Re: EAR Datasource javax.naming.NameNoFoundException
Posted by zsaade <zs...@path-solutions.com>.
Dear jgallimore
Find below <tomee-home>\apps\earFile\jarFile\META-INF\openejb-jar.xml:
<?xml version="1.0"?>
<openejb-jar xmlns="http://www.openejb.org/openejb-jar/1.1">
<ejb-deployment ejb-name="TestEJB" deployment-id="TestEJB"
container-id="Default Stateless Container" >
<resource-link res-ref-name="services" res-id="Default JDBC Database"/>
</ejb-deployment>
</openejb-jar>
I changes the the openejb-jar.xml format based on the below links
specifications:
http://tomee.apache.org/details-on-openejb-jar.html
https://github.com/apache/tomee/blob/master/container/openejb-core/src/main/resources/schema/openejb-jar.xsd
and <tomee-home>\apps\earFile\jarFile\META-INF\ejb-jar.xml:
<enterprise-beans>
<session id="Test">
<description>Describe here the session bean Administration</description>
<display-name>test/testEJB</display-name>
<ejb-name>TestEJB</ejb-name>
<home>test.TestHome</home>
<remote>test.Test</remote>
<ejb-class>test.TestEJB</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
<env-entry>
<env-entry-name>name1</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>value1</env-entry-value>
</env-entry>
<resource-ref>
<res-ref-name>services</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Application</res-auth>
</resource-ref>
</session>
</enterprise-beans>
And <tomee-home>\conf\tomee.xml :
<?xml version="1.0" encoding="UTF-8"?>
<tomee>
<Deployments dir="apps" />
<Resource id="services" type="javax.sql.DataSource">
....................
</Resource>
</tomee>
and in my TestEJB i'm doing the below Connection Call:
DataSource datasource = (DataSource) initContext.lookup("services");
And i'm still getting the below exception:
javax.naming.NameNotFoundException: NAme [services] is nt bound in this
Context. Unable to find [services].
Best Regards
--
Sent from: http://tomee-openejb.979440.n4.nabble.com/TomEE-Users-f979441.html
Re: EAR Datasource javax.naming.NameNoFoundException
Posted by Jonathan Gallimore <jo...@gmail.com>.
Apologies for the delay. If you want do the lookup in your web-tier
(servlets, etc) in web.xml you want a resource-ref like this one:
https://github.com/jgallimore/tomee/blob/master/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/org/apache/openejb/arquillian/tests/cmp/sample/web.xml#L43-L47
<resource-ref>
<res-ref-name>db/services</res-ref-name> . <!-- 1 -->
<res-type>javax.sql.DataSource</res-type>
<mapped-name>services</mapped-name> . <!-- 2 -->
</resource-ref>
The res-ref-name [1] is where the datasource will appear under
java:comp/env. The mapped-name [2] should match the resource ID in
tomee.xml.
For your EJB layer, you want to do something similar in ejb-jar.xml:
<enterprise-beans>
<session>
<ejb-name>MoviesBean</ejb-name>
<home>org.apache.openejb.arquillian.tests.cmp.sample.MoviesBusinessHome</home>
<remote>org.apache.openejb.arquillian.tests.cmp.sample.MoviesBusiness</remote>
<ejb-class>org.apache.openejb.arquillian.tests.cmp.sample.MoviesBusinessBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
<resource-ref>
<res-ref-name>db/DataSource</res-ref-name> <!-- 1 -->
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<security-identity>
<use-caller-identity/>
</security-identity>
</session>
....
[1] is where the datasource should be available under java:comp/env
and in openejb-jar.xml you can link the res-ref-name [1] to the actual
datasource:
<openejb-jar xmlns="http://www.openejb.org/xml/ns/openejb-jar-2.1">
<enterprise-beans>
<session>
<ejb-name>MoviesBean</ejb-name>
<resource-ref>
<ref-name>db/DataSource</ref-name> <!-- 1 -->
<resource-link>services</resource-link> <!-- 2 -->
</resource-ref>
</session>
[1] is where the datasource should be available under java:comp/env
[2] is should match the resource ID in tomee.xml.
If you're able to move to EJB 3.0+, injection using @Resource is definitely
a lot easier :-)
Hope that helps.
Jon
On Thu, Feb 14, 2019 at 7:51 AM zsaade <zs...@path-solutions.com> wrote:
> Dear jgallimore
>
> Thanks a lot for you reply; I tried the below:
>
> Context initContext = new InitialContext();
> DataSource ds = (DataSource)
> initContext.lookup("openejb:Resource/services");
> this.ConnectDataSource = ds;
>
> But I received the below exception:
>
> javax.naming.NameNotFoundException: Name "Resource/services" not found.
>
> PS: Waiting your Example.
>
> Best Regards
>
>
>
> --
> Sent from:
> http://tomee-openejb.979440.n4.nabble.com/TomEE-Users-f979441.html
>
Re: EAR Datasource javax.naming.NameNoFoundException
Posted by zsaade <zs...@path-solutions.com>.
Dear jgallimore
Thanks a lot for you reply; I tried the below:
Context initContext = new InitialContext();
DataSource ds = (DataSource)
initContext.lookup("openejb:Resource/services");
this.ConnectDataSource = ds;
But I received the below exception:
javax.naming.NameNotFoundException: Name "Resource/services" not found.
PS: Waiting your Example.
Best Regards
--
Sent from: http://tomee-openejb.979440.n4.nabble.com/TomEE-Users-f979441.html
Re: EAR Datasource javax.naming.NameNoFoundException
Posted by Jonathan Gallimore <jo...@gmail.com>.
Hi
You can likely look this up using "openejb:Resource/services", but that
won't be portable. A better solution is to reference the data source in
web.xml and map it to a name under java:comp/env.
I'll post an example in a couple of hours to help you out.
Jon
On Wed, 13 Feb 2019, 18:03 zsaade <zsaade@path-solutions.com wrote:
> Dear All
>
> I have an EAR file that i'm deploying under
> <apache-tomee-plume-7.1.0-home>\apps folder, I added the the below
> Datasource configuration in the tomee.xml file located under
> <tomee-home>\conf:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <tomee>
> <Deployments dir="apps" />
> <Resource id="services" type="javax.sql.DataSource">
> jdbcDriver oracle.jdbc.OracleDriver
> jdbcUrl jdbc:oracle:thin:@//db-server:1521/ORA11
> userName test_server
> password test_server
> jtaManaged true
> defaultAutoCommit true
> </Resource>
> </tomee>
>
> In my EJB i'm calling the datasource as per the below code:
>
> Context initContext = new InitialContext();
> DataSource ds = (DataSource) initContext.lookup("services");
> this.ConnectDataSource = ds;
>
> But When i'm starting TomeEE i'm getting the below exception:
>
> javax.naming.NameNoFoundException: Name [services] is not bound in this
> Context. Unable to find [services.]
>
> Kindly advice
>
>
> Best Regards
>
>
>
>
>
> --
> Sent from:
> http://tomee-openejb.979440.n4.nabble.com/TomEE-Users-f979441.html
>