You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by tonywestonuk <to...@totspics.com> on 2016/05/02 11:44:54 UTC

Resource-link to global resource

Hi...   This question was asked before a few years back, though I am unable
to get it going.

In my server.xml, I have a GlobalNamingResources, which defines a
datasource.  I want to make this available to my web app.  In Tomcat, this
can be done with ResourceLink.  At the moment, I can see it in JNDI as  
openejb:Resource/jdbc/gblmetadata  , but I cant use this reference directly
in my @Resource(name="openejb:Resource/jdbc/gblmetadata")


How do I do this in Tomee?....   Reading the previous post,  I think I need
to add something to resources.xml, which is in my web-inf folder.  An Alias
definition? but, I cant find any documentation about how to set this up. 
Can you give me an example?

Thanks. 







--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/Resource-link-to-global-resource-tp4678304.html
Sent from the TomEE Users mailing list archive at Nabble.com.

Re: Resource-link to global resource

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

GlobalNamingResources should be available like in tomcat in java:comp.
About tomee resource you can access them in openejb:Resource subtree or
java:openejb/Resource.

A sample reproducing your issue can help to dig into it. Just with your
description it sounds like you maybe want to migrate from that to tomee.xml
to define the datasource.


Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
<http://www.tomitribe.com> | JavaEE Factory
<https://javaeefactory-rmannibucau.rhcloud.com>

2016-05-02 11:44 GMT+02:00 tonywestonuk <to...@totspics.com>:

> Hi...   This question was asked before a few years back, though I am unable
> to get it going.
>
> In my server.xml, I have a GlobalNamingResources, which defines a
> datasource.  I want to make this available to my web app.  In Tomcat, this
> can be done with ResourceLink.  At the moment, I can see it in JNDI as
> openejb:Resource/jdbc/gblmetadata  , but I cant use this reference directly
> in my @Resource(name="openejb:Resource/jdbc/gblmetadata")
>
>
> How do I do this in Tomee?....   Reading the previous post,  I think I need
> to add something to resources.xml, which is in my web-inf folder.  An Alias
> definition? but, I cant find any documentation about how to set this up.
> Can you give me an example?
>
> Thanks.
>
>
>
>
>
>
>
> --
> View this message in context:
> http://tomee-openejb.979440.n4.nabble.com/Resource-link-to-global-resource-tp4678304.html
> Sent from the TomEE Users mailing list archive at Nabble.com.
>

Re: Resource-link to global resource

Posted by Romain Manni-Bucau <rm...@gmail.com>.
You can define a datasource in tomee.xml and add aliases="jdbc/puName,..."
attributr on Resource tag to say the datasource also matches some other
names.
Le 2 mai 2016 13:16, "tonywestonuk" <to...@totspics.com> a écrit :

> Ok.... This is my use case.
>
> I have a microservice style system, each microservice is hosted in a
> different context, rather than the more mainstream different process.  Each
> 'microservice' needs access to its own database, which is provided by the
> application server.
>
> I tried creating a context.xml in the conf directory, containing all
> database information. However this was just duplicated for each context.
> and my database didn't like haveing so many connections.
>
> Whats needed is a set of database resources, maintained by tomee, which
> each
> app can pick one to be a default.... that is presented when you inject a
> Datasource resource, or when refered to using persistance.xml.
>
>
>
>
> --
> View this message in context:
> http://tomee-openejb.979440.n4.nabble.com/Resource-link-to-global-resource-tp4678304p4678309.html
> Sent from the TomEE Users mailing list archive at Nabble.com.
>

Re: Resource-link to global resource

Posted by tonywestonuk <to...@totspics.com>.
Ok.... This is my use case.

I have a microservice style system, each microservice is hosted in a
different context, rather than the more mainstream different process.  Each
'microservice' needs access to its own database, which is provided by the
application server.

I tried creating a context.xml in the conf directory, containing all
database information. However this was just duplicated for each context. 
and my database didn't like haveing so many connections.  

Whats needed is a set of database resources, maintained by tomee, which each
app can pick one to be a default.... that is presented when you inject a
Datasource resource, or when refered to using persistance.xml.




--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/Resource-link-to-global-resource-tp4678304p4678309.html
Sent from the TomEE Users mailing list archive at Nabble.com.

Re: Resource-link to global resource

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Le 2 mai 2016 13:12, "tonywestonuk" <to...@totspics.com> a écrit :
>
> @Resource(name="openejb:Resource/jdbc/gblmetadata")  doesn't find it.
> However
>
> @Resource(lookup="openejb:Resource/jdbc/gblmetadata") does!! :-D
>

Name is concerted to an internal name. Lookup queries jndi directly.

>
> Next problem.   Is there any way I can avoid not having to put this
> @Resource annotation at all?  - If I dont put it, the default HSQL
database
> is found.   Is there somewhere where I can configure that I want my own
> global datasource to be the default, rather than the built in on? .....
and
> if possible, maybe even turn off the HSQL db.?
>

Sure putting openejb offline will not auto create resource but also means
you dudnt wire properly resources to let tomee link it correctly.

> Thanks.
>
>
>
> --
> View this message in context:
http://tomee-openejb.979440.n4.nabble.com/Resource-link-to-global-resource-tp4678304p4678308.html
> Sent from the TomEE Users mailing list archive at Nabble.com.

Re: Resource-link to global resource

Posted by tonywestonuk <to...@totspics.com>.
@Resource(name="openejb:Resource/jdbc/gblmetadata")  doesn't find it. 
However

@Resource(lookup="openejb:Resource/jdbc/gblmetadata") does!! :-D


Next problem.   Is there any way I can avoid not having to put this
@Resource annotation at all?  - If I dont put it, the default HSQL database
is found.   Is there somewhere where I can configure that I want my own
global datasource to be the default, rather than the built in on? ..... and
if possible, maybe even turn off the HSQL db.?

Thanks.



--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/Resource-link-to-global-resource-tp4678304p4678308.html
Sent from the TomEE Users mailing list archive at Nabble.com.