You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Daniel Plappert <pl...@denkformat.de> on 2010/07/19 17:19:58 UTC

where to declare the datasource?

Hi!

It is possible to declare the datasource in the servlet.xml and reference it in the web.xml of the application (via jndi). Or one can declare it in the application itself, i.e. in application-context.xml. The first one declares the datasource for all applications deployed in this servlet-container, the second one is only for the application.
Is there a good reason for declaring the datasource in servlet.xml, other than to "share" the datasource with multiple applications? Shouldn't every application have their own datasource? 
Which type of declaration do you prefer?


Greetings,
Daniel




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


Re: where to declare the datasource?

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

Daniel,

On 7/19/2010 11:19 AM, Daniel Plappert wrote:
> It is possible to declare the datasource in the servlet.xml and
> reference it in the web.xml of the application (via jndi)[?]

Assuming you meant "server.xml", then yes, you can define it globally
and reference it locally. Look under the configuration reference for
your Tomcat version for "Global Resources" a.k.a. <GlobalNamingResources>.

> Or one can declare it in the application itself, i.e. in 
> application-context.xml. The first one declares the datasource for 
> all applications deployed in this servlet-container, the second one 
> is only for the application.

Right.

> Is there a good reason for declaring the datasource in servlet.xml,
> other than to "share" the datasource with multiple applications?

I can think of several reasons you might want to do this, including but
not limited to any of the following:

1. There really is a database that should be shared by a number of
different applications, and they should all use the same pool of connections

2. The developers have no idea about the data source connection details,
and expect the server admins to provide the configuration

#2 isn't really a good reason to do this, though: the server admins can
always provide or override a webapp-provided context.xml file in order
to include the correct configuration. This allows you to change the
configuration without starting the entire server: only a webapp
restart/redeploy is necessary.

> Shouldn't every application have their own datasource?

That depends entirely on your own requirements.

> Which type of declaration do you prefer?

I would recommend per-webapp configuration, but sometimes it makes sense
to share a connection pool across many webapps. Again, it depends
entirely upon your own requirements.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkxEdocACgkQ9CaO5/Lv0PDOSQCfcNKLkXM+F/IkEgkXa7aWDwxH
zlAAoLFCl9AJ0YEheFotb+mfC7ZZV6Za
=xB3n
-----END PGP SIGNATURE-----

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