On 28/04/2025 16:35, Christopher Schultz wrote:
ABT,
On 4/28/25 9:05 AM, A Name wrote:
We are looking at adding a second instance of our app (named
differently --
myappA and myappB) to our Tomcat 9. We currently have the app
installed at
a number of customer locations, we are looking at dropping 1 app
Currently, our database connections are established inside the GLOBAL
web.xml in /conf/web.xml - and have been forever. This was a design
decision made long ago - that way the app doesn't have a separate
configuration for each location - it is the same app WAR file, and the
connections are established at the server.
Our customer doesn't want any code changes - is there a way to have some
sort of conditional statements in the web.xml?
No, but maybe you don't need them.
JDBC configurations are never stored in web.xml, regardless of location.
So maybe you are talking about <datasource-ref> or something like that?
Unless your application is collecting some configuration from web.xml
and then making its own connections or establish its own JDBC data
source, your configuration should be in META-INF/context.xml in the web
application. If you don't want to bundle that with your web application,
you can deploy a site-specific configuration file in Tomcat's conf/
[Engine]/[Host]/[appname].xml file which contains this configuration.
Then your web.xml only has to reference the name of the data-source in
datasource-ref which can be static. The local configuration file gives
the details, and web.xml references them.
Will this approach not work for you?
Or if we set it up so Tomcat is hosting 2 sites (www.sitea.com/myapp and
www.siteb.com/myapp) and have the global web.xml with different settings
based on host/site?
As Mark says, "global is global".
Thinking about this some more and to expand on Chris's excellent suggestion.
You can define multiple JDBC connection pools in conf/web.xml and then
use <ResourceLink /> in the context.xml
https://tomcat.apache.org/tomcat-11.0-doc/config/globalresources.html#Resource_Links
There are also Host level configuration files for context.xml and
web.xml that apply to all applications within that Host.
HTH,
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org