On 29/08/2024 14:19, Marcelo de Sena Lacerda wrote:
Understanding ResorceLink property inheritance

My scenario is this, I have several applications running on a tomcat, all of 
them access the same database I want them to be inside the same pool so the 
number of connections oppened can be sensibly managed using the same 
parameters. All of that works as of now.

Additionally I also want them to connect to the database using different users 
so that's easier to identify which application is running which processes in 
the database.

My understanding is that I could do that with setting a Resource in my 
server.xml with all the pool configuration parameters set and a ResourceLink in 
the context.xml of the application with only the username and password set.

Yes, but only under specific circumstances.

https://tomcat.apache.org/tomcat-11.0-doc/config/context.html#Resource_Links

That more or less works. Indeed if setup the scenario described in the above paragraph I can set a 
different username and password for the Resource in the  ResourceLink, however it seems that tomcat 
"forgets" every other parameter of the Resource driverClass,url, and, more importantly 
maxActive, maxIdle, initialSize all gets "forgotten" by tomcat.

Why is that happening?

We need to see the resource definition in server.xml as there may be changes required there as well.

I'm using tomcat 10.1.28 with java 22.0.2 from openjdk.

This is the ResourceLink that inherits all parameters from server.xml:

<ResourceLink
             name="jdbc/mydatabase"
             global="jdbc/mydatabase"
             type="javax.sql.DataSource"
/>

And this is one that forgets all parent parameters:

<ResourceLink
             name="jdbc/mydatabase"
             global="jdbc/mydatabase"
             type="javax.sql.DataSource"
             driverClassName="..."
             url="..."
             username="..."
             password="..."
             factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
/>

Wrong factory.
driverClassName is not a valid attribute for a ResourceLink
url is not a valid attribute for a ResourceLink

Mark


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

Reply via email to