You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Francesco Viscomi <fv...@gmail.com> on 2018/08/01 19:22:55 UTC

configuring jndi datasource

Hi all,
I'm using tomcat 8.5 and I need to configure a datasource in tomcat;

If a configure it in the contex.xml file under conf directory using the tag
<resource> everythings goes well.

But if I configure it in the server.xml file under the conf directory,  a
message tell me that the resource that i have called jdbc/dataSource in not
bound in this context;

Now I'm asking why, Tomcat cannot detect that the datasource is configured
in the server.xml file?
And why i should have to configure the resource in the context.xml under
the conf direcory?

thanks really much




-- 
Ing. Viscomi Francesco

Re: configuring jndi datasource

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Francesco,

On 8/1/18 4:10 PM, Francesco Viscomi wrote:
> I do not understand unfortunately; I have only one file under conf
> directory: contex.xml;

You shouldn't be modifying that file, because it will apply to all
contexts. Instead, you should create an application-specific file
under {your-web-app-root}/META-INF/context.xml

If you put your <Resource> there, you (a) won't have to restart Tomcat
to make changes, (b) won't have to map from global-resource to
local-resource and (c) won't make that resource available to all
webapps -- only that ONE webapp where the <Resource> is defined.

> So every application installed on this instance of  tomcat can view
> the resource; It is like I have configured the resource globally; I
> can understand it, if every application has it's own context.xml
> file but indeed I have just one context.xml file;
> 
> could you please explain to me maybe with an example why can be
> security concerns?

A global resource is available to all applications. Maybe you have
some applications that should not have access to jdbc/MyDataSource? It
is better to do either of the following:

1. define a global resource (in server.xml) and individually-map the
resource to each application as appropriate

OR

2. define the resource locally, in the webapp-specific context file
which is META-INF/context.xml

The CATALINA_BASE/conf/context.xml file is the global template for all
META-INF/context.xml files. You really shouldn't modify
CATALINA_BASE/conf/context.xml at all.

- -chris

> 2018-08-01 21:31 GMT+02:00 Mark Thomas <ma...@apache.org>:
> 
>> On 01/08/18 20:22, Francesco Viscomi wrote:
>>> Hi all, I'm using tomcat 8.5 and I need to configure a
>>> datasource in tomcat;
>>> 
>>> If a configure it in the contex.xml file under conf directory
>>> using the
>> tag
>>> <resource> everythings goes well.
>>> 
>>> But if I configure it in the server.xml file under the conf
>>> directory,  a message tell me that the resource that i have
>>> called jdbc/dataSource in
>> not
>>> bound in this context;
>>> 
>>> Now I'm asking why, Tomcat cannot detect that the datasource
>>> is
>> configured
>>> in the server.xml file? And why i should have to configure the
>>> resource in the context.xml under the conf direcory?
>> 
>> If you define a resource globally in server.xml you have to
>> explicitly link it to the web application(s) you want to have
>> access to it.
>> 
>> Global resources are deliberately not visible to all web
>> applications as in many installations that would create security
>> concerns.
>> 
>> Mark
>> 
>> ---------------------------------------------------------------------
>>
>> 
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>> 
>> 
> 
> 
-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAltiHEcACgkQHPApP6U8
pFhPYxAArZcItJL9aZuJiHWaGwClUjc0aZiPiOdLr+KHnYQCVv+5cngmFpCjzN68
LA98HwiXyJ0U4HdGMFT3QJr6LKaOyxCWN2QkMUoOGAs/VmJ9IBYqaJJr4ShBiIf8
JjOgDFyXIh+Q7xjFhrFlUU4ob+2ODoDFRW4L59lcilxAcaxQ8CRYjQFBhGIrnlAU
PAMlNg7MKkF3Lf2zFX9pQd0RR13RpwykKnO5LMYLlGQjw+2uOeV/29VtdWSWiZ0e
NRCnhz9vhHrhn79iI/LnnoKgK1YMVPE+JwM5apzqYJs0ejxaglo5Mbr4aZNu6Qn/
8K3KBRPLXXSaY6my/bSSej4LRkDaUXG0qVVmH6GZm2Xu9ierc/G6+KBqjuR8iG8G
jh7NR18vHoB3bK4MGabVFy0NbKzjaaUJ2ef8DF0l7sb/L1eJJd9Ce9Nn3yy/DvB6
goiy8E8Zu7twOfPvmatmAhselGrJwufVm7zR6WUktl16afwjJFT8OX+p4WzbwiOp
VLyo/W+C5eUkJtv64DrkC+N7DLipScN6gqBx0PcezPkVf8dHqDjD+r5Ws5MYx6/x
tD0hTGqicUSQup/0gPf0j1w3tbx2Au21uQWgDaSTMR1yGGfs/HjV+nil6w3/RnTA
Y/qBiUoiZthUCTLGbHJ1W1+2Rt0XPPwNYo9gju6rU3jZ4UYvr3w=
=B1iU
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: configuring jndi datasource

Posted by Mark Thomas <ma...@apache.org>.
On 01/08/18 21:10, Francesco Viscomi wrote:
> I do not understand unfortunately;
> I have only one file under conf directory: contex.xml;
> So every application installed on this instance of  tomcat can view the
> resource; It is like I have configured the resource globally;

No it is not.

Configured in conf/context.xml means one instance of the resource for
each web application.

Configured in server.xml means one instance of the resource shared
between those web applications that you choose to link to it.

> I can
> understand it, if every application has it's own context.xml file but
> indeed I have just one context.xml file;
> 
> could you please explain to me maybe with an example why can be security
> concerns?

Shared hosting environments.

Mark


> 
> thanks
> 
> 2018-08-01 21:31 GMT+02:00 Mark Thomas <ma...@apache.org>:
> 
>> On 01/08/18 20:22, Francesco Viscomi wrote:
>>> Hi all,
>>> I'm using tomcat 8.5 and I need to configure a datasource in tomcat;
>>>
>>> If a configure it in the contex.xml file under conf directory using the
>> tag
>>> <resource> everythings goes well.
>>>
>>> But if I configure it in the server.xml file under the conf directory,  a
>>> message tell me that the resource that i have called jdbc/dataSource in
>> not
>>> bound in this context;
>>>
>>> Now I'm asking why, Tomcat cannot detect that the datasource is
>> configured
>>> in the server.xml file?
>>> And why i should have to configure the resource in the context.xml under
>>> the conf direcory?
>>
>> If you define a resource globally in server.xml you have to explicitly
>> link it to the web application(s) you want to have access to it.
>>
>> Global resources are deliberately not visible to all web applications as
>> in many installations that would create security concerns.
>>
>> Mark
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: configuring jndi datasource

Posted by Francesco Viscomi <fv...@gmail.com>.
I do not understand unfortunately;
I have only one file under conf directory: contex.xml;
So every application installed on this instance of  tomcat can view the
resource; It is like I have configured the resource globally; I can
understand it, if every application has it's own context.xml file but
indeed I have just one context.xml file;

could you please explain to me maybe with an example why can be security
concerns?

thanks

2018-08-01 21:31 GMT+02:00 Mark Thomas <ma...@apache.org>:

> On 01/08/18 20:22, Francesco Viscomi wrote:
> > Hi all,
> > I'm using tomcat 8.5 and I need to configure a datasource in tomcat;
> >
> > If a configure it in the contex.xml file under conf directory using the
> tag
> > <resource> everythings goes well.
> >
> > But if I configure it in the server.xml file under the conf directory,  a
> > message tell me that the resource that i have called jdbc/dataSource in
> not
> > bound in this context;
> >
> > Now I'm asking why, Tomcat cannot detect that the datasource is
> configured
> > in the server.xml file?
> > And why i should have to configure the resource in the context.xml under
> > the conf direcory?
>
> If you define a resource globally in server.xml you have to explicitly
> link it to the web application(s) you want to have access to it.
>
> Global resources are deliberately not visible to all web applications as
> in many installations that would create security concerns.
>
> Mark
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>


-- 
Ing. Viscomi Francesco

Re: configuring jndi datasource

Posted by Mark Thomas <ma...@apache.org>.
On 01/08/18 20:22, Francesco Viscomi wrote:
> Hi all,
> I'm using tomcat 8.5 and I need to configure a datasource in tomcat;
> 
> If a configure it in the contex.xml file under conf directory using the tag
> <resource> everythings goes well.
> 
> But if I configure it in the server.xml file under the conf directory,  a
> message tell me that the resource that i have called jdbc/dataSource in not
> bound in this context;
> 
> Now I'm asking why, Tomcat cannot detect that the datasource is configured
> in the server.xml file?
> And why i should have to configure the resource in the context.xml under
> the conf direcory?

If you define a resource globally in server.xml you have to explicitly
link it to the web application(s) you want to have access to it.

Global resources are deliberately not visible to all web applications as
in many installations that would create security concerns.

Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org