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 <[email protected]> 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
>

Reply via email to