On 29/08/2024 15:52, Marcelo de Sena Lacerda wrote:
The resource definition in server.xml
...
<GlobalNamingResources>
...
<Resource name="jdbc/mydatabase"
global="jdbc/mydatabase"
auth="Container"
type="javax.sql.DataSource"
removeAbandoned="true"
removeAbandonedTimeout="120"
maxActive="5"
maxIdle="5"
initialSize="0"
minIdle="0"
maxWait="200"
timeBetweenEvictionRunsMillis="30000"
minEvictableIdleTimeMillis="60000"
maxAge="120000"
validatorClassName="..."
testOnBorrow="true"
validationInterval="0"
fairQueue="false"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
alternateUsernameAllowed="true"
username="..." password="..."
driverClassName="..."
url="..."/>
OK. The global resource looks good.
...
*
Wrong factory.
*
driverClassName is not a valid attribute for a ResourceLink
*
url is not a valid attribute for a ResourceLink
From reading the documentation that was also my initial thought, however if I
write my ResourceLink like this:
<ResourceLink
name="jdbc/mydatabase"
global="jdbc/mydatabase"
type="javax.sql.DataSource"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
username="..."
password="..."
/>
The factory should be org.apache.naming.factory.DataSourceLinkFactory in
the ResoucreLink. Otherwise the above looks OK to me.
(Note: I'm basing this off reading the documentation - I haven't tested
that it actually works).
Mark
I get the following error:
javax.naming.NamingException: Unexpected exception resolving reference [Root
exception is java.sql.SQLException: The url cannot be null
When my code tries to obtain the DataSource from the context:
DataSource ds = (DataSource)envContext.lookup("jdbc/mydatabase");
________________________________
De: Mark Thomas <ma...@apache.org>
Enviado: quinta-feira, 29 de agosto de 2024 10:30
Para: users@tomcat.apache.org <users@tomcat.apache.org>
Assunto: Re: Understanding ResorceLink property inheritance
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
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org