You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Rick Noel <RN...@westwoodone.com.INVALID> on 2024/03/29 15:56:43 UTC

RE: [EXT]Re: how to define database resource in just context.xml or server.xml

If have the resource defined in
CATALINA_BASE/conf/context.xml
And 
CATALINA_BASE/conf/server.xml

Rick Noel
Systems Programmer | Westwood One
RNoel@westwoodone.com

-----Original Message-----
From: Christopher Schultz <ch...@christopherschultz.net> 
Sent: Friday, March 29, 2024 11:47 AM
To: users@tomcat.apache.org
Subject: [EXT]Re: how to define database resource in just context.xml or server.xml

Rick,

On 3/29/24 09:48, Rick Noel wrote:
> Can someone tell me why I need to have my database source defined in 
> both my context.xml and server.xml? I thought we are suppose to define 
> it in only one location?
It's definitely not a requirement to specify it in both places.

> I can only log into my app if I have it defined in both my context.xml 
> and server.xml
>
> Below  is my database resource   as defined in server.xml..........
>
> I have xxx out postgres URL for security reasons
>
> <GlobalNamingResources>
>
>
>
>                   <Resource  name="jdbc/app-pool" auth="Container"
>                                        type="javax.sql.DataSource"  driverClassName="org.postgresql.Driver"
>                                        url="jdbc:postgresql://xxxxxxxxxxx"
>                                        username="postgres" password="postgres4now"
>                                        maxTotal="30"  maxIdle="30" maxWaitMillis="-1"
>                                        removeAbandonedOnBorrow="true" removeAbandonedTimeout="90"
>                                        testOnBorrow="true"  validationQuery="select 1" validationQueryTimeout="30000"
>                                        testWhileIdle="true"  timeBetweenEvictionRunsMillis="60000"
>                                        testOnReturn="true"
>             />
>
>
>    </GlobalNamingResources>
>
>
>
> Below is my database resource   as defined in context.xml
>
>
> <Context    >
>
>      <Resources allowLinking="true" />
>
>
>
>     <Resource  name="jdbc/app-pool" auth="Container"
>                       type="javax.sql.DataSource"  driverClassName="org.postgresql.Driver"
>                       url="jdbc:postgresql://xxxxxxxxxx
>                       username="postgres" password="postgres4now"
>                       maxTotal="30"  maxIdle="30" maxWaitMillis="-1"
>                       removeAbandonedOnBorrow="true" removeAbandonedTimeout="90"
>                         testOnBorrow="true"  validationQuery="select 1" validationQueryTimeout="30000"
>                         testWhileIdle="true"  timeBetweenEvictionRunsMillis="60000"
>                         testOnReturn="true"
>             />

Which context.xml are you talking about? The one in CATALINA_BASE/context.xml or the one in your application's META-INF/context.xml?

Have you defined your <Context> in CATALINA_BASE/conf/server.xml, or are you using only META-INF/context.xml?

-chris

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

CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you know the sender and you are sure the content is safe. Please report the message using the Report Message feature in your email client if you believe the email is suspicious.


RE: FW: [EXT]Re: how to define database resource in just context.xml or server.xml

Posted by Rick Noel <RN...@westwoodone.com.INVALID>.
Yeah I like the idea of using the Resourcelink  in the context.xml and then keep the defining of that datasource in the server.xml

Rick Noel
Systems Programmer | Westwood One
RNoel@westwoodone.com

-----Original Message-----
From: Christopher Schultz <ch...@christopherschultz.net> 
Sent: Friday, March 29, 2024 2:23 PM
To: users@tomcat.apache.org
Subject: Re: FW: [EXT]Re: how to define database resource in just context.xml or server.xml

Rick,

On 3/29/24 14:05, Rick Noel wrote:
> Chris,
> 
> I found I could use a ResourceLink element and put it in my context.xml file.
> The name in that ResourceLink is the name of resource that I have fully defined in my server.xml.
> Sot the context.xml points to the fully define resource which is in my 
> server.xml

That's definitely a possibility as well.

I work on a small team and so separating the JDBC definition from the link doesn't make much sense so we don't do it. We also don't like polluting our server.xml file so everything goes into META-INF/context.xml.

You really should never change CATALINA_BASE/conf/context.xml, though.

-chris

> So snippet from my context.xml file is.............
> 
> <Context    >
> 
>      <Resources allowLinking="true" />
>      
>    
>     
>     <ResourceLink
>                 name="jdbc/app-pool"
>                 global="jdbc/app-pool"
>                type="javax.sql.DataSource"   />
> 
> 
> And snippet from my server.xml is.........
> 
> <Server port="18105" shutdown="SHUTDOWN">
>    <GlobalNamingResources>
> 
>      <Resource  name="jdbc/app-pool" auth="Container"
> 		       type="javax.sql.DataSource"  driverClassName="org.postgresql.Driver"
> 		       url="jdbc:postgresql://xxxxxxxxx"
> 		       username="xxxxx" password="xxxxxx"
> 		       maxTotal="30"  maxIdle="30" maxWaitMillis="-1"
> 		       removeAbandonedOnBorrow="true" removeAbandonedTimeout="90"
> 		       testOnBorrow="true"  validationQuery="select 1" validationQueryTimeout="30000"
> 		       testWhileIdle="true"  timeBetweenEvictionRunsMillis="60000"
> 		       testOnReturn="true"  />	
>       
> 
> 
> Rick Noel
> Systems Programmer | Westwood One
> RNoel@westwoodone.com
> 
> -----Original Message-----
> From: Rick Noel
> Sent: Friday, March 29, 2024 11:57 AM
> To: Tomcat Users List <us...@tomcat.apache.org>
> Subject: RE: [EXT]Re: how to define database resource in just 
> context.xml or server.xml
> 
> If have the resource defined in
> CATALINA_BASE/conf/context.xml
> And
> CATALINA_BASE/conf/server.xml
> 
> Rick Noel
> Systems Programmer | Westwood One
> RNoel@westwoodone.com
> 
> -----Original Message-----
> From: Christopher Schultz <ch...@christopherschultz.net>
> Sent: Friday, March 29, 2024 11:47 AM
> To: users@tomcat.apache.org
> Subject: [EXT]Re: how to define database resource in just context.xml 
> or server.xml
> 
> Rick,
> 
> On 3/29/24 09:48, Rick Noel wrote:
>> Can someone tell me why I need to have my database source defined in 
>> both my context.xml and server.xml? I thought we are suppose to 
>> define it in only one location?
> It's definitely not a requirement to specify it in both places.
> 
>> I can only log into my app if I have it defined in both my 
>> context.xml and server.xml
>>
>> Below  is my database resource   as defined in server.xml..........
>>
>> I have xxx out postgres URL for security reasons
>>
>> <GlobalNamingResources>
>>
>>
>>
>>                    <Resource  name="jdbc/app-pool" auth="Container"
>>                                         type="javax.sql.DataSource"  driverClassName="org.postgresql.Driver"
>>                                         url="jdbc:postgresql://xxxxxxxxxxx"
>>                                         username="postgres" password="postgres4now"
>>                                         maxTotal="30"  maxIdle="30" maxWaitMillis="-1"
>>                                         removeAbandonedOnBorrow="true" removeAbandonedTimeout="90"
>>                                         testOnBorrow="true"  validationQuery="select 1" validationQueryTimeout="30000"
>>                                         testWhileIdle="true"  timeBetweenEvictionRunsMillis="60000"
>>                                         testOnReturn="true"
>>              />
>>
>>
>>     </GlobalNamingResources>
>>
>>
>>
>> Below is my database resource   as defined in context.xml
>>
>>
>> <Context    >
>>
>>       <Resources allowLinking="true" />
>>
>>
>>
>>      <Resource  name="jdbc/app-pool" auth="Container"
>>                        type="javax.sql.DataSource"  driverClassName="org.postgresql.Driver"
>>                        url="jdbc:postgresql://xxxxxxxxxx
>>                        username="postgres" password="postgres4now"
>>                        maxTotal="30"  maxIdle="30" maxWaitMillis="-1"
>>                        removeAbandonedOnBorrow="true" removeAbandonedTimeout="90"
>>                          testOnBorrow="true"  validationQuery="select 1" validationQueryTimeout="30000"
>>                          testWhileIdle="true"  timeBetweenEvictionRunsMillis="60000"
>>                          testOnReturn="true"
>>              />
> 
> Which context.xml are you talking about? The one in CATALINA_BASE/context.xml or the one in your application's META-INF/context.xml?
> 
> Have you defined your <Context> in CATALINA_BASE/conf/server.xml, or are you using only META-INF/context.xml?
> 
> -chris
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
> CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you know the sender and you are sure the content is safe. Please report the message using the Report Message feature in your email client if you believe the email is suspicious.
> 
> 
> ---------------------------------------------------------------------
> 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: FW: [EXT]Re: how to define database resource in just context.xml or server.xml

Posted by Christopher Schultz <ch...@christopherschultz.net>.
Rick,

On 3/29/24 14:05, Rick Noel wrote:
> Chris,
> 
> I found I could use a ResourceLink element and put it in my context.xml file.
> The name in that ResourceLink is the name of resource that I have fully defined in my server.xml.
> Sot the context.xml points to the fully define resource which is in my server.xml

That's definitely a possibility as well.

I work on a small team and so separating the JDBC definition from the 
link doesn't make much sense so we don't do it. We also don't like 
polluting our server.xml file so everything goes into META-INF/context.xml.

You really should never change CATALINA_BASE/conf/context.xml, though.

-chris

> So snippet from my context.xml file is.............
> 
> <Context    >
> 
>      <Resources allowLinking="true" />
>      
>    
>     
>     <ResourceLink
>                 name="jdbc/app-pool"
>                 global="jdbc/app-pool"
>                type="javax.sql.DataSource"   />
> 
> 
> And snippet from my server.xml is.........
> 
> <Server port="18105" shutdown="SHUTDOWN">
>    <GlobalNamingResources>
> 
>      <Resource  name="jdbc/app-pool" auth="Container"
> 		       type="javax.sql.DataSource"  driverClassName="org.postgresql.Driver"
> 		       url="jdbc:postgresql://xxxxxxxxx"
> 		       username="xxxxx" password="xxxxxx"
> 		       maxTotal="30"  maxIdle="30" maxWaitMillis="-1"
> 		       removeAbandonedOnBorrow="true" removeAbandonedTimeout="90"
> 		       testOnBorrow="true"  validationQuery="select 1" validationQueryTimeout="30000"
> 		       testWhileIdle="true"  timeBetweenEvictionRunsMillis="60000"
> 		       testOnReturn="true"  />	
>       
> 
> 
> Rick Noel
> Systems Programmer | Westwood One
> RNoel@westwoodone.com
> 
> -----Original Message-----
> From: Rick Noel
> Sent: Friday, March 29, 2024 11:57 AM
> To: Tomcat Users List <us...@tomcat.apache.org>
> Subject: RE: [EXT]Re: how to define database resource in just context.xml or server.xml
> 
> If have the resource defined in
> CATALINA_BASE/conf/context.xml
> And
> CATALINA_BASE/conf/server.xml
> 
> Rick Noel
> Systems Programmer | Westwood One
> RNoel@westwoodone.com
> 
> -----Original Message-----
> From: Christopher Schultz <ch...@christopherschultz.net>
> Sent: Friday, March 29, 2024 11:47 AM
> To: users@tomcat.apache.org
> Subject: [EXT]Re: how to define database resource in just context.xml or server.xml
> 
> Rick,
> 
> On 3/29/24 09:48, Rick Noel wrote:
>> Can someone tell me why I need to have my database source defined in
>> both my context.xml and server.xml? I thought we are suppose to define
>> it in only one location?
> It's definitely not a requirement to specify it in both places.
> 
>> I can only log into my app if I have it defined in both my context.xml
>> and server.xml
>>
>> Below  is my database resource   as defined in server.xml..........
>>
>> I have xxx out postgres URL for security reasons
>>
>> <GlobalNamingResources>
>>
>>
>>
>>                    <Resource  name="jdbc/app-pool" auth="Container"
>>                                         type="javax.sql.DataSource"  driverClassName="org.postgresql.Driver"
>>                                         url="jdbc:postgresql://xxxxxxxxxxx"
>>                                         username="postgres" password="postgres4now"
>>                                         maxTotal="30"  maxIdle="30" maxWaitMillis="-1"
>>                                         removeAbandonedOnBorrow="true" removeAbandonedTimeout="90"
>>                                         testOnBorrow="true"  validationQuery="select 1" validationQueryTimeout="30000"
>>                                         testWhileIdle="true"  timeBetweenEvictionRunsMillis="60000"
>>                                         testOnReturn="true"
>>              />
>>
>>
>>     </GlobalNamingResources>
>>
>>
>>
>> Below is my database resource   as defined in context.xml
>>
>>
>> <Context    >
>>
>>       <Resources allowLinking="true" />
>>
>>
>>
>>      <Resource  name="jdbc/app-pool" auth="Container"
>>                        type="javax.sql.DataSource"  driverClassName="org.postgresql.Driver"
>>                        url="jdbc:postgresql://xxxxxxxxxx
>>                        username="postgres" password="postgres4now"
>>                        maxTotal="30"  maxIdle="30" maxWaitMillis="-1"
>>                        removeAbandonedOnBorrow="true" removeAbandonedTimeout="90"
>>                          testOnBorrow="true"  validationQuery="select 1" validationQueryTimeout="30000"
>>                          testWhileIdle="true"  timeBetweenEvictionRunsMillis="60000"
>>                          testOnReturn="true"
>>              />
> 
> Which context.xml are you talking about? The one in CATALINA_BASE/context.xml or the one in your application's META-INF/context.xml?
> 
> Have you defined your <Context> in CATALINA_BASE/conf/server.xml, or are you using only META-INF/context.xml?
> 
> -chris
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
> CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you know the sender and you are sure the content is safe. Please report the message using the Report Message feature in your email client if you believe the email is suspicious.
> 
> 
> ---------------------------------------------------------------------
> 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


FW: [EXT]Re: how to define database resource in just context.xml or server.xml

Posted by Rick Noel <RN...@westwoodone.com.INVALID>.
Chris,

I found I could use a ResourceLink element and put it in my context.xml file.
The name in that ResourceLink is the name of resource that I have fully defined in my server.xml.
Sot the context.xml points to the fully define resource which is in my server.xml

So snippet from my context.xml file is.............

<Context    >

    <Resources allowLinking="true" />
    
  
   
   <ResourceLink
               name="jdbc/app-pool"
               global="jdbc/app-pool"
              type="javax.sql.DataSource"   />


And snippet from my server.xml is.........

<Server port="18105" shutdown="SHUTDOWN">
  <GlobalNamingResources>

    <Resource  name="jdbc/app-pool" auth="Container"
		       type="javax.sql.DataSource"  driverClassName="org.postgresql.Driver"
		       url="jdbc:postgresql://xxxxxxxxx"
		       username="xxxxx" password="xxxxxx" 
		       maxTotal="30"  maxIdle="30" maxWaitMillis="-1"
		       removeAbandonedOnBorrow="true" removeAbandonedTimeout="90"           
		       testOnBorrow="true"  validationQuery="select 1" validationQueryTimeout="30000"
		       testWhileIdle="true"  timeBetweenEvictionRunsMillis="60000"
		       testOnReturn="true"  />	
     


Rick Noel
Systems Programmer | Westwood One
RNoel@westwoodone.com

-----Original Message-----
From: Rick Noel 
Sent: Friday, March 29, 2024 11:57 AM
To: Tomcat Users List <us...@tomcat.apache.org>
Subject: RE: [EXT]Re: how to define database resource in just context.xml or server.xml

If have the resource defined in
CATALINA_BASE/conf/context.xml
And
CATALINA_BASE/conf/server.xml

Rick Noel
Systems Programmer | Westwood One
RNoel@westwoodone.com

-----Original Message-----
From: Christopher Schultz <ch...@christopherschultz.net>
Sent: Friday, March 29, 2024 11:47 AM
To: users@tomcat.apache.org
Subject: [EXT]Re: how to define database resource in just context.xml or server.xml

Rick,

On 3/29/24 09:48, Rick Noel wrote:
> Can someone tell me why I need to have my database source defined in 
> both my context.xml and server.xml? I thought we are suppose to define 
> it in only one location?
It's definitely not a requirement to specify it in both places.

> I can only log into my app if I have it defined in both my context.xml 
> and server.xml
>
> Below  is my database resource   as defined in server.xml..........
>
> I have xxx out postgres URL for security reasons
>
> <GlobalNamingResources>
>
>
>
>                   <Resource  name="jdbc/app-pool" auth="Container"
>                                        type="javax.sql.DataSource"  driverClassName="org.postgresql.Driver"
>                                        url="jdbc:postgresql://xxxxxxxxxxx"
>                                        username="postgres" password="postgres4now"
>                                        maxTotal="30"  maxIdle="30" maxWaitMillis="-1"
>                                        removeAbandonedOnBorrow="true" removeAbandonedTimeout="90"
>                                        testOnBorrow="true"  validationQuery="select 1" validationQueryTimeout="30000"
>                                        testWhileIdle="true"  timeBetweenEvictionRunsMillis="60000"
>                                        testOnReturn="true"
>             />
>
>
>    </GlobalNamingResources>
>
>
>
> Below is my database resource   as defined in context.xml
>
>
> <Context    >
>
>      <Resources allowLinking="true" />
>
>
>
>     <Resource  name="jdbc/app-pool" auth="Container"
>                       type="javax.sql.DataSource"  driverClassName="org.postgresql.Driver"
>                       url="jdbc:postgresql://xxxxxxxxxx
>                       username="postgres" password="postgres4now"
>                       maxTotal="30"  maxIdle="30" maxWaitMillis="-1"
>                       removeAbandonedOnBorrow="true" removeAbandonedTimeout="90"
>                         testOnBorrow="true"  validationQuery="select 1" validationQueryTimeout="30000"
>                         testWhileIdle="true"  timeBetweenEvictionRunsMillis="60000"
>                         testOnReturn="true"
>             />

Which context.xml are you talking about? The one in CATALINA_BASE/context.xml or the one in your application's META-INF/context.xml?

Have you defined your <Context> in CATALINA_BASE/conf/server.xml, or are you using only META-INF/context.xml?

-chris

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

CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you know the sender and you are sure the content is safe. Please report the message using the Report Message feature in your email client if you believe the email is suspicious.


RE: [EXT]Re: how to define database resource in just context.xml or server.xml

Posted by Rick Noel <RN...@westwoodone.com.INVALID>.
Yes and that is just what we are trying to do.  On our dev servers all five different applications share the same database.
So it would seem best to have the resource link in the context.xml and not complicate things up by putting the database link in each web application's web.xml.

The idea being that a developer working on one application would think if he changed the web.xml for his application, hey maybe I should change the other application's web.xml also

Rick Noel
Systems Programmer | Westwood One
RNoel@westwoodone.com

-----Original Message-----
From: Mark Thomas <ma...@apache.org> 
Sent: Sunday, March 31, 2024 1:55 PM
To: users@tomcat.apache.org
Subject: Re: [EXT]Re: how to define database resource in just context.xml or server.xml

On 29/03/2024 21:58, Christopher Schultz wrote:
> Rick,
> 
> On 3/29/24 14:33, Rick Noel wrote:
>> Our application is really a suite of 5applications.  And the 
>> server.xml  I am talking about is on our dev machine, where we want 
>> to run all 5 apps on the one web server.
>>
>> The context.xml has global enviroiment variables (like mail server 
>> related vars) that all the dev applications use. All the different 
>> dev applications also use the same database.
>>
>> So that is why we define resources in the context.xml  file
> It sounds like you really *do* want to define the JDBC/JNDI resource 
> in server.xml and the link it to your applications.
> 
> I think the correct way to do that is by defining it in server.xml and 
> then linking it through your applications' WEB-INF/web.xml files.
> 
> You should not have to touch CATALINA_BASE/conf/context.xml.

The only reason you might want to touch context.xml is if you want to provide the same resource link to all web applications rather than have to specify it in each web application.

Mark

> 
> -chris
> 
>> -----Original Message-----
>> From: Christopher Schultz <ch...@christopherschultz.net>
>> Sent: Friday, March 29, 2024 2:21 PM
>> To: Tomcat Users List <us...@tomcat.apache.org>; Rick Noel 
>> <RN...@westwoodone.com.INVALID>
>> Subject: Re: [EXT]Re: how to define database resource in just 
>> context.xml or server.xml
>>
>> Rick,
>>
>> On 3/29/24 11:56, Rick Noel wrote:
>>> If have the resource defined in
>>> CATALINA_BASE/conf/context.xml
>>> And
>>> CATALINA_BASE/conf/server.xml
>>
>> You really shouldn't have anything custom in 
>> CATALINA_BASE/conf/context.xml. That will affect every application 
>> deployed on the server. Perhaps you only have a single application 
>> deployed, but things can get really confusing when you edit that file.
>> It also makes upgrades more difficult.
>>
>> I would recommend taking your <Resource> from 
>> CATALINA_BASE/conf/context.xml and putting it into the proper place:
>> your application's META-INF/context.xml file. You will need to 
>> surround it with <Context> ... </Context> since that file defines the 
>> context.
>>
>> If you have <Context> in your CATALINA_BASE/conf/server.xml file, you 
>> should remove it. If you want to disable auto-deploy, then you can 
>> always copy your application's META-INF/context.xml file into 
>> CATALINA_BASE/conf/[engine]/[host]/[contextpath].xml.
>>
>> Finally, you should be able to delete your <Resource> from your 
>> CATALINA_BASE/conf/server.xml file entirely.
>>
>> Do you have anything in your web.xml that is related? For example:
>>
>>     <resource-ref>
>>       <res-ref-name>jdbc/foo</res-ref-name>
>>       <res-type>javax.sql.DataSource</res-type>
>>       <res-auth>Container</res-auth>
>>     </resource-ref>
>>
>> I have one of those in my web.xml, but it's not clear to be whether 
>> or not I actually need it. I have *one* of them but my application 
>> uses two different JDBC resources. Both are declared in 
>> META-INF/context.xml and both are available to the application.
>>
>> I think you need to use <resource-ref> in web.xml when you define 
>> "global naming resources" in server.xml. But if you put them into 
>> META-INF/context.xml it's obvious that (a) they aren't global and (b) 
>> the application expects them.
>>
>> So I would remove any global naming resources you may have in 
>> server.xml and also remove anything you don't need in web.xml.
>>
>> Doing all this will make upgrading Tomcat much easier.
>>
>> -chris
>>
>>> -----Original Message-----
>>> From: Christopher Schultz <ch...@christopherschultz.net>
>>> Sent: Friday, March 29, 2024 11:47 AM
>>> To: users@tomcat.apache.org
>>> Subject: [EXT]Re: how to define database resource in just 
>>> context.xml or server.xml
>>>
>>> Rick,
>>>
>>> On 3/29/24 09:48, Rick Noel wrote:
>>>> Can someone tell me why I need to have my database source defined 
>>>> in both my context.xml and server.xml? I thought we are suppose to 
>>>> define it in only one location?
>>> It's definitely not a requirement to specify it in both places.
>>>
>>>> I can only log into my app if I have it defined in both my 
>>>> context.xml and server.xml
>>>>
>>>> Below  is my database resource   as defined in server.xml..........
>>>>
>>>> I have xxx out postgres URL for security reasons
>>>>
>>>> <GlobalNamingResources>
>>>>
>>>>
>>>>
>>>>                     <Resource  name="jdbc/app-pool" auth="Container"
>>>>                                          
>>>> type="javax.sql.DataSource"  driverClassName="org.postgresql.Driver"
>>>>                                          
>>>> url="jdbc:postgresql://xxxxxxxxxxx"
>>>>                                          username="postgres" 
>>>> password="postgres4now"
>>>>                                          maxTotal="30"  maxIdle="30" 
>>>> maxWaitMillis="-1"
>>>>                                          
>>>> removeAbandonedOnBorrow="true" removeAbandonedTimeout="90"
>>>>                                          testOnBorrow="true"  
>>>> validationQuery="select 1" validationQueryTimeout="30000"
>>>>                                          testWhileIdle="true"  
>>>> timeBetweenEvictionRunsMillis="60000"
>>>>                                          testOnReturn="true"
>>>>               />
>>>>
>>>>
>>>>      </GlobalNamingResources>
>>>>
>>>>
>>>>
>>>> Below is my database resource   as defined in context.xml
>>>>
>>>>
>>>> <Context    >
>>>>
>>>>        <Resources allowLinking="true" />
>>>>
>>>>
>>>>
>>>>       <Resource  name="jdbc/app-pool" auth="Container"
>>>>                         type="javax.sql.DataSource"  
>>>> driverClassName="org.postgresql.Driver"
>>>>                         url="jdbc:postgresql://xxxxxxxxxx
>>>>                         username="postgres" password="postgres4now"
>>>>                         maxTotal="30"  maxIdle="30" maxWaitMillis="-1"
>>>>                         removeAbandonedOnBorrow="true" 
>>>> removeAbandonedTimeout="90"
>>>>                           testOnBorrow="true"  
>>>> validationQuery="select 1" validationQueryTimeout="30000"
>>>>                           testWhileIdle="true"  
>>>> timeBetweenEvictionRunsMillis="60000"
>>>>                           testOnReturn="true"
>>>>               />
>>>
>>> Which context.xml are you talking about? The one in 
>>> CATALINA_BASE/context.xml or the one in your application's 
>>> META-INF/context.xml?
>>>
>>> Have you defined your <Context> in CATALINA_BASE/conf/server.xml, or 
>>> are you using only META-INF/context.xml?
>>>
>>> -chris
>>>
>>> --------------------------------------------------------------------
>>> - To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>> For additional commands, e-mail: users-help@tomcat.apache.org
>>>
>>> CAUTION: This email originated from outside of the organization. Do 
>>> not click links or open attachments unless you know the sender and 
>>> you are sure the content is safe. Please report the message using 
>>> the Report Message feature in your email client if you believe the 
>>> email is suspicious.
>>>
>>>
>>> --------------------------------------------------------------------
>>> - 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
>>
>>
>> ---------------------------------------------------------------------
>> 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
> 

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


Re: [EXT]Re: how to define database resource in just context.xml or server.xml

Posted by Mark Thomas <ma...@apache.org>.
On 29/03/2024 21:58, Christopher Schultz wrote:
> Rick,
> 
> On 3/29/24 14:33, Rick Noel wrote:
>> Our application is really a suite of 5applications.  And the
>> server.xml  I am talking about is on our dev machine, where we want
>> to run all 5 apps on the one web server.
>>
>> The context.xml has global enviroiment variables (like mail server
>> related vars) that all the dev applications use. All the different
>> dev applications also use the same database.
>>
>> So that is why we define resources in the context.xml  file
> It sounds like you really *do* want to define the JDBC/JNDI resource in 
> server.xml and the link it to your applications.
> 
> I think the correct way to do that is by defining it in server.xml and 
> then linking it through your applications' WEB-INF/web.xml files.
> 
> You should not have to touch CATALINA_BASE/conf/context.xml.

The only reason you might want to touch context.xml is if you want to 
provide the same resource link to all web applications rather than have 
to specify it in each web application.

Mark

> 
> -chris
> 
>> -----Original Message-----
>> From: Christopher Schultz <ch...@christopherschultz.net>
>> Sent: Friday, March 29, 2024 2:21 PM
>> To: Tomcat Users List <us...@tomcat.apache.org>; Rick Noel 
>> <RN...@westwoodone.com.INVALID>
>> Subject: Re: [EXT]Re: how to define database resource in just 
>> context.xml or server.xml
>>
>> Rick,
>>
>> On 3/29/24 11:56, Rick Noel wrote:
>>> If have the resource defined in
>>> CATALINA_BASE/conf/context.xml
>>> And
>>> CATALINA_BASE/conf/server.xml
>>
>> You really shouldn't have anything custom in 
>> CATALINA_BASE/conf/context.xml. That will affect every application 
>> deployed on the server. Perhaps you only have a single application 
>> deployed, but things can get really confusing when you edit that file.
>> It also makes upgrades more difficult.
>>
>> I would recommend taking your <Resource> from 
>> CATALINA_BASE/conf/context.xml and putting it into the proper place:
>> your application's META-INF/context.xml file. You will need to 
>> surround it with <Context> ... </Context> since that file defines the 
>> context.
>>
>> If you have <Context> in your CATALINA_BASE/conf/server.xml file, you 
>> should remove it. If you want to disable auto-deploy, then you can 
>> always copy your application's META-INF/context.xml file into 
>> CATALINA_BASE/conf/[engine]/[host]/[contextpath].xml.
>>
>> Finally, you should be able to delete your <Resource> from your 
>> CATALINA_BASE/conf/server.xml file entirely.
>>
>> Do you have anything in your web.xml that is related? For example:
>>
>>     <resource-ref>
>>       <res-ref-name>jdbc/foo</res-ref-name>
>>       <res-type>javax.sql.DataSource</res-type>
>>       <res-auth>Container</res-auth>
>>     </resource-ref>
>>
>> I have one of those in my web.xml, but it's not clear to be whether or 
>> not I actually need it. I have *one* of them but my application uses 
>> two different JDBC resources. Both are declared in 
>> META-INF/context.xml and both are available to the application.
>>
>> I think you need to use <resource-ref> in web.xml when you define 
>> "global naming resources" in server.xml. But if you put them into 
>> META-INF/context.xml it's obvious that (a) they aren't global and (b) 
>> the application expects them.
>>
>> So I would remove any global naming resources you may have in 
>> server.xml and also remove anything you don't need in web.xml.
>>
>> Doing all this will make upgrading Tomcat much easier.
>>
>> -chris
>>
>>> -----Original Message-----
>>> From: Christopher Schultz <ch...@christopherschultz.net>
>>> Sent: Friday, March 29, 2024 11:47 AM
>>> To: users@tomcat.apache.org
>>> Subject: [EXT]Re: how to define database resource in just context.xml
>>> or server.xml
>>>
>>> Rick,
>>>
>>> On 3/29/24 09:48, Rick Noel wrote:
>>>> Can someone tell me why I need to have my database source defined in
>>>> both my context.xml and server.xml? I thought we are suppose to
>>>> define it in only one location?
>>> It's definitely not a requirement to specify it in both places.
>>>
>>>> I can only log into my app if I have it defined in both my
>>>> context.xml and server.xml
>>>>
>>>> Below  is my database resource   as defined in server.xml..........
>>>>
>>>> I have xxx out postgres URL for security reasons
>>>>
>>>> <GlobalNamingResources>
>>>>
>>>>
>>>>
>>>>                     <Resource  name="jdbc/app-pool" auth="Container"
>>>>                                          
>>>> type="javax.sql.DataSource"  driverClassName="org.postgresql.Driver"
>>>>                                          
>>>> url="jdbc:postgresql://xxxxxxxxxxx"
>>>>                                          username="postgres" 
>>>> password="postgres4now"
>>>>                                          maxTotal="30"  maxIdle="30" 
>>>> maxWaitMillis="-1"
>>>>                                          
>>>> removeAbandonedOnBorrow="true" removeAbandonedTimeout="90"
>>>>                                          testOnBorrow="true"  
>>>> validationQuery="select 1" validationQueryTimeout="30000"
>>>>                                          testWhileIdle="true"  
>>>> timeBetweenEvictionRunsMillis="60000"
>>>>                                          testOnReturn="true"
>>>>               />
>>>>
>>>>
>>>>      </GlobalNamingResources>
>>>>
>>>>
>>>>
>>>> Below is my database resource   as defined in context.xml
>>>>
>>>>
>>>> <Context    >
>>>>
>>>>        <Resources allowLinking="true" />
>>>>
>>>>
>>>>
>>>>       <Resource  name="jdbc/app-pool" auth="Container"
>>>>                         type="javax.sql.DataSource"  
>>>> driverClassName="org.postgresql.Driver"
>>>>                         url="jdbc:postgresql://xxxxxxxxxx
>>>>                         username="postgres" password="postgres4now"
>>>>                         maxTotal="30"  maxIdle="30" maxWaitMillis="-1"
>>>>                         removeAbandonedOnBorrow="true" 
>>>> removeAbandonedTimeout="90"
>>>>                           testOnBorrow="true"  
>>>> validationQuery="select 1" validationQueryTimeout="30000"
>>>>                           testWhileIdle="true"  
>>>> timeBetweenEvictionRunsMillis="60000"
>>>>                           testOnReturn="true"
>>>>               />
>>>
>>> Which context.xml are you talking about? The one in 
>>> CATALINA_BASE/context.xml or the one in your application's 
>>> META-INF/context.xml?
>>>
>>> Have you defined your <Context> in CATALINA_BASE/conf/server.xml, or 
>>> are you using only META-INF/context.xml?
>>>
>>> -chris
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>> For additional commands, e-mail: users-help@tomcat.apache.org
>>>
>>> CAUTION: This email originated from outside of the organization. Do 
>>> not click links or open attachments unless you know the sender and 
>>> you are sure the content is safe. Please report the message using the 
>>> Report Message feature in your email client if you believe the email 
>>> is suspicious.
>>>
>>>
>>> ---------------------------------------------------------------------
>>> 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
>>
>>
>> ---------------------------------------------------------------------
>> 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
> 

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


Re: [EXT]Re: how to define database resource in just context.xml or server.xml

Posted by Christopher Schultz <ch...@christopherschultz.net>.
Rick,

On 3/29/24 14:33, Rick Noel wrote:
> Our application is really a suite of 5applications.  And the
> server.xml  I am talking about is on our dev machine, where we want
> to run all 5 apps on the one web server.
> 
> The context.xml has global enviroiment variables (like mail server
> related vars) that all the dev applications use. All the different
> dev applications also use the same database.
> 
> So that is why we define resources in the context.xml  file
It sounds like you really *do* want to define the JDBC/JNDI resource in 
server.xml and the link it to your applications.

I think the correct way to do that is by defining it in server.xml and 
then linking it through your applications' WEB-INF/web.xml files.

You should not have to touch CATALINA_BASE/conf/context.xml.

-chris

> -----Original Message-----
> From: Christopher Schultz <ch...@christopherschultz.net>
> Sent: Friday, March 29, 2024 2:21 PM
> To: Tomcat Users List <us...@tomcat.apache.org>; Rick Noel <RN...@westwoodone.com.INVALID>
> Subject: Re: [EXT]Re: how to define database resource in just context.xml or server.xml
> 
> Rick,
> 
> On 3/29/24 11:56, Rick Noel wrote:
>> If have the resource defined in
>> CATALINA_BASE/conf/context.xml
>> And
>> CATALINA_BASE/conf/server.xml
> 
> You really shouldn't have anything custom in CATALINA_BASE/conf/context.xml. That will affect every application deployed on the server. Perhaps you only have a single application deployed, but things can get really confusing when you edit that file.
> It also makes upgrades more difficult.
> 
> I would recommend taking your <Resource> from CATALINA_BASE/conf/context.xml and putting it into the proper place:
> your application's META-INF/context.xml file. You will need to surround it with <Context> ... </Context> since that file defines the context.
> 
> If you have <Context> in your CATALINA_BASE/conf/server.xml file, you should remove it. If you want to disable auto-deploy, then you can always copy your application's META-INF/context.xml file into CATALINA_BASE/conf/[engine]/[host]/[contextpath].xml.
> 
> Finally, you should be able to delete your <Resource> from your CATALINA_BASE/conf/server.xml file entirely.
> 
> Do you have anything in your web.xml that is related? For example:
> 
>     <resource-ref>
>       <res-ref-name>jdbc/foo</res-ref-name>
>       <res-type>javax.sql.DataSource</res-type>
>       <res-auth>Container</res-auth>
>     </resource-ref>
> 
> I have one of those in my web.xml, but it's not clear to be whether or not I actually need it. I have *one* of them but my application uses two different JDBC resources. Both are declared in META-INF/context.xml and both are available to the application.
> 
> I think you need to use <resource-ref> in web.xml when you define "global naming resources" in server.xml. But if you put them into META-INF/context.xml it's obvious that (a) they aren't global and (b) the application expects them.
> 
> So I would remove any global naming resources you may have in server.xml and also remove anything you don't need in web.xml.
> 
> Doing all this will make upgrading Tomcat much easier.
> 
> -chris
> 
>> -----Original Message-----
>> From: Christopher Schultz <ch...@christopherschultz.net>
>> Sent: Friday, March 29, 2024 11:47 AM
>> To: users@tomcat.apache.org
>> Subject: [EXT]Re: how to define database resource in just context.xml
>> or server.xml
>>
>> Rick,
>>
>> On 3/29/24 09:48, Rick Noel wrote:
>>> Can someone tell me why I need to have my database source defined in
>>> both my context.xml and server.xml? I thought we are suppose to
>>> define it in only one location?
>> It's definitely not a requirement to specify it in both places.
>>
>>> I can only log into my app if I have it defined in both my
>>> context.xml and server.xml
>>>
>>> Below  is my database resource   as defined in server.xml..........
>>>
>>> I have xxx out postgres URL for security reasons
>>>
>>> <GlobalNamingResources>
>>>
>>>
>>>
>>>                     <Resource  name="jdbc/app-pool" auth="Container"
>>>                                          type="javax.sql.DataSource"  driverClassName="org.postgresql.Driver"
>>>                                          url="jdbc:postgresql://xxxxxxxxxxx"
>>>                                          username="postgres" password="postgres4now"
>>>                                          maxTotal="30"  maxIdle="30" maxWaitMillis="-1"
>>>                                          removeAbandonedOnBorrow="true" removeAbandonedTimeout="90"
>>>                                          testOnBorrow="true"  validationQuery="select 1" validationQueryTimeout="30000"
>>>                                          testWhileIdle="true"  timeBetweenEvictionRunsMillis="60000"
>>>                                          testOnReturn="true"
>>>               />
>>>
>>>
>>>      </GlobalNamingResources>
>>>
>>>
>>>
>>> Below is my database resource   as defined in context.xml
>>>
>>>
>>> <Context    >
>>>
>>>        <Resources allowLinking="true" />
>>>
>>>
>>>
>>>       <Resource  name="jdbc/app-pool" auth="Container"
>>>                         type="javax.sql.DataSource"  driverClassName="org.postgresql.Driver"
>>>                         url="jdbc:postgresql://xxxxxxxxxx
>>>                         username="postgres" password="postgres4now"
>>>                         maxTotal="30"  maxIdle="30" maxWaitMillis="-1"
>>>                         removeAbandonedOnBorrow="true" removeAbandonedTimeout="90"
>>>                           testOnBorrow="true"  validationQuery="select 1" validationQueryTimeout="30000"
>>>                           testWhileIdle="true"  timeBetweenEvictionRunsMillis="60000"
>>>                           testOnReturn="true"
>>>               />
>>
>> Which context.xml are you talking about? The one in CATALINA_BASE/context.xml or the one in your application's META-INF/context.xml?
>>
>> Have you defined your <Context> in CATALINA_BASE/conf/server.xml, or are you using only META-INF/context.xml?
>>
>> -chris
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>> CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you know the sender and you are sure the content is safe. Please report the message using the Report Message feature in your email client if you believe the email is suspicious.
>>
>>
>> ---------------------------------------------------------------------
>> 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
> 
> 
> ---------------------------------------------------------------------
> 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: [EXT]Re: how to define database resource in just context.xml or server.xml

Posted by Rick Noel <RN...@westwoodone.com.INVALID>.
Chris,
Our application is really a suite of 5applications.  And the server.xml  I am talking about is on our dev machine, where we want to run all 5 apps on the one web server. 

The context.xml has global enviroiment variables (like mail server related vars) that all the dev applications use.
All the different dev applications also use the same database.

So that is why we define resources in the context.xml  file

Rick Noel
Systems Programmer | Westwood One
RNoel@westwoodone.com

-----Original Message-----
From: Christopher Schultz <ch...@christopherschultz.net> 
Sent: Friday, March 29, 2024 2:21 PM
To: Tomcat Users List <us...@tomcat.apache.org>; Rick Noel <RN...@westwoodone.com.INVALID>
Subject: Re: [EXT]Re: how to define database resource in just context.xml or server.xml

Rick,

On 3/29/24 11:56, Rick Noel wrote:
> If have the resource defined in
> CATALINA_BASE/conf/context.xml
> And
> CATALINA_BASE/conf/server.xml

You really shouldn't have anything custom in CATALINA_BASE/conf/context.xml. That will affect every application deployed on the server. Perhaps you only have a single application deployed, but things can get really confusing when you edit that file. 
It also makes upgrades more difficult.

I would recommend taking your <Resource> from CATALINA_BASE/conf/context.xml and putting it into the proper place: 
your application's META-INF/context.xml file. You will need to surround it with <Context> ... </Context> since that file defines the context.

If you have <Context> in your CATALINA_BASE/conf/server.xml file, you should remove it. If you want to disable auto-deploy, then you can always copy your application's META-INF/context.xml file into CATALINA_BASE/conf/[engine]/[host]/[contextpath].xml.

Finally, you should be able to delete your <Resource> from your CATALINA_BASE/conf/server.xml file entirely.

Do you have anything in your web.xml that is related? For example:

   <resource-ref>
     <res-ref-name>jdbc/foo</res-ref-name>
     <res-type>javax.sql.DataSource</res-type>
     <res-auth>Container</res-auth>
   </resource-ref>

I have one of those in my web.xml, but it's not clear to be whether or not I actually need it. I have *one* of them but my application uses two different JDBC resources. Both are declared in META-INF/context.xml and both are available to the application.

I think you need to use <resource-ref> in web.xml when you define "global naming resources" in server.xml. But if you put them into META-INF/context.xml it's obvious that (a) they aren't global and (b) the application expects them.

So I would remove any global naming resources you may have in server.xml and also remove anything you don't need in web.xml.

Doing all this will make upgrading Tomcat much easier.

-chris

> -----Original Message-----
> From: Christopher Schultz <ch...@christopherschultz.net>
> Sent: Friday, March 29, 2024 11:47 AM
> To: users@tomcat.apache.org
> Subject: [EXT]Re: how to define database resource in just context.xml 
> or server.xml
> 
> Rick,
> 
> On 3/29/24 09:48, Rick Noel wrote:
>> Can someone tell me why I need to have my database source defined in 
>> both my context.xml and server.xml? I thought we are suppose to 
>> define it in only one location?
> It's definitely not a requirement to specify it in both places.
> 
>> I can only log into my app if I have it defined in both my 
>> context.xml and server.xml
>>
>> Below  is my database resource   as defined in server.xml..........
>>
>> I have xxx out postgres URL for security reasons
>>
>> <GlobalNamingResources>
>>
>>
>>
>>                    <Resource  name="jdbc/app-pool" auth="Container"
>>                                         type="javax.sql.DataSource"  driverClassName="org.postgresql.Driver"
>>                                         url="jdbc:postgresql://xxxxxxxxxxx"
>>                                         username="postgres" password="postgres4now"
>>                                         maxTotal="30"  maxIdle="30" maxWaitMillis="-1"
>>                                         removeAbandonedOnBorrow="true" removeAbandonedTimeout="90"
>>                                         testOnBorrow="true"  validationQuery="select 1" validationQueryTimeout="30000"
>>                                         testWhileIdle="true"  timeBetweenEvictionRunsMillis="60000"
>>                                         testOnReturn="true"
>>              />
>>
>>
>>     </GlobalNamingResources>
>>
>>
>>
>> Below is my database resource   as defined in context.xml
>>
>>
>> <Context    >
>>
>>       <Resources allowLinking="true" />
>>
>>
>>
>>      <Resource  name="jdbc/app-pool" auth="Container"
>>                        type="javax.sql.DataSource"  driverClassName="org.postgresql.Driver"
>>                        url="jdbc:postgresql://xxxxxxxxxx
>>                        username="postgres" password="postgres4now"
>>                        maxTotal="30"  maxIdle="30" maxWaitMillis="-1"
>>                        removeAbandonedOnBorrow="true" removeAbandonedTimeout="90"
>>                          testOnBorrow="true"  validationQuery="select 1" validationQueryTimeout="30000"
>>                          testWhileIdle="true"  timeBetweenEvictionRunsMillis="60000"
>>                          testOnReturn="true"
>>              />
> 
> Which context.xml are you talking about? The one in CATALINA_BASE/context.xml or the one in your application's META-INF/context.xml?
> 
> Have you defined your <Context> in CATALINA_BASE/conf/server.xml, or are you using only META-INF/context.xml?
> 
> -chris
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
> CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you know the sender and you are sure the content is safe. Please report the message using the Report Message feature in your email client if you believe the email is suspicious.
> 
> 
> ---------------------------------------------------------------------
> 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: [EXT]Re: how to define database resource in just context.xml or server.xml

Posted by Christopher Schultz <ch...@christopherschultz.net>.
Rick,

On 3/29/24 11:56, Rick Noel wrote:
> If have the resource defined in
> CATALINA_BASE/conf/context.xml
> And
> CATALINA_BASE/conf/server.xml

You really shouldn't have anything custom in 
CATALINA_BASE/conf/context.xml. That will affect every application 
deployed on the server. Perhaps you only have a single application 
deployed, but things can get really confusing when you edit that file. 
It also makes upgrades more difficult.

I would recommend taking your <Resource> from 
CATALINA_BASE/conf/context.xml and putting it into the proper place: 
your application's META-INF/context.xml file. You will need to surround 
it with <Context> ... </Context> since that file defines the context.

If you have <Context> in your CATALINA_BASE/conf/server.xml file, you 
should remove it. If you want to disable auto-deploy, then you can 
always copy your application's META-INF/context.xml file into 
CATALINA_BASE/conf/[engine]/[host]/[contextpath].xml.

Finally, you should be able to delete your <Resource> from your 
CATALINA_BASE/conf/server.xml file entirely.

Do you have anything in your web.xml that is related? For example:

   <resource-ref>
     <res-ref-name>jdbc/foo</res-ref-name>
     <res-type>javax.sql.DataSource</res-type>
     <res-auth>Container</res-auth>
   </resource-ref>

I have one of those in my web.xml, but it's not clear to be whether or 
not I actually need it. I have *one* of them but my application uses two 
different JDBC resources. Both are declared in META-INF/context.xml and 
both are available to the application.

I think you need to use <resource-ref> in web.xml when you define 
"global naming resources" in server.xml. But if you put them into 
META-INF/context.xml it's obvious that (a) they aren't global and (b) 
the application expects them.

So I would remove any global naming resources you may have in server.xml 
and also remove anything you don't need in web.xml.

Doing all this will make upgrading Tomcat much easier.

-chris

> -----Original Message-----
> From: Christopher Schultz <ch...@christopherschultz.net>
> Sent: Friday, March 29, 2024 11:47 AM
> To: users@tomcat.apache.org
> Subject: [EXT]Re: how to define database resource in just context.xml or server.xml
> 
> Rick,
> 
> On 3/29/24 09:48, Rick Noel wrote:
>> Can someone tell me why I need to have my database source defined in
>> both my context.xml and server.xml? I thought we are suppose to define
>> it in only one location?
> It's definitely not a requirement to specify it in both places.
> 
>> I can only log into my app if I have it defined in both my context.xml
>> and server.xml
>>
>> Below  is my database resource   as defined in server.xml..........
>>
>> I have xxx out postgres URL for security reasons
>>
>> <GlobalNamingResources>
>>
>>
>>
>>                    <Resource  name="jdbc/app-pool" auth="Container"
>>                                         type="javax.sql.DataSource"  driverClassName="org.postgresql.Driver"
>>                                         url="jdbc:postgresql://xxxxxxxxxxx"
>>                                         username="postgres" password="postgres4now"
>>                                         maxTotal="30"  maxIdle="30" maxWaitMillis="-1"
>>                                         removeAbandonedOnBorrow="true" removeAbandonedTimeout="90"
>>                                         testOnBorrow="true"  validationQuery="select 1" validationQueryTimeout="30000"
>>                                         testWhileIdle="true"  timeBetweenEvictionRunsMillis="60000"
>>                                         testOnReturn="true"
>>              />
>>
>>
>>     </GlobalNamingResources>
>>
>>
>>
>> Below is my database resource   as defined in context.xml
>>
>>
>> <Context    >
>>
>>       <Resources allowLinking="true" />
>>
>>
>>
>>      <Resource  name="jdbc/app-pool" auth="Container"
>>                        type="javax.sql.DataSource"  driverClassName="org.postgresql.Driver"
>>                        url="jdbc:postgresql://xxxxxxxxxx
>>                        username="postgres" password="postgres4now"
>>                        maxTotal="30"  maxIdle="30" maxWaitMillis="-1"
>>                        removeAbandonedOnBorrow="true" removeAbandonedTimeout="90"
>>                          testOnBorrow="true"  validationQuery="select 1" validationQueryTimeout="30000"
>>                          testWhileIdle="true"  timeBetweenEvictionRunsMillis="60000"
>>                          testOnReturn="true"
>>              />
> 
> Which context.xml are you talking about? The one in CATALINA_BASE/context.xml or the one in your application's META-INF/context.xml?
> 
> Have you defined your <Context> in CATALINA_BASE/conf/server.xml, or are you using only META-INF/context.xml?
> 
> -chris
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
> CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you know the sender and you are sure the content is safe. Please report the message using the Report Message feature in your email client if you believe the email is suspicious.
> 
> 
> ---------------------------------------------------------------------
> 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