Good day fellow Apache Tomcat users

I have recently had reason to set a Postgres DataSource via the Tomcat JNDI
api. My experiments have been largely unsuccessful, unfortunately I hope
you are able to help me. I thank you in advance for taking the time to read
this.

I am coming to this problem in a rather backward way. I am not familiar
with deploying web applications through Tomcat, this is something that was
done in a semi-automated way and replicated so that a close look has not
really been necessary for me until now.

To provide a bit of context, the web server where I am trying to set up a
Postgres JNDI globally shared connection is running running several DSpace
webapps.

I have been largely assisted by the official documentation here [0] and
here [1] as well as DSpace documentation here [2] and discussion on a user
mailing list for DSpace here [3].

I am running:

CentOS Linux release 7.8.2003
Tomcat 9.0.12
PostgreSQL 9.5.23
openjdk version "1.8.0_262"
OpenJDK Runtime Environment (build 1.8.0_262-b10)


   1.  I downloaded postgresql-42.2.18.jar from
   https://jdbc.postgresql.org/download/postgresql-42.2.18.jar and placed
   it in /home/lib/dspace/apache-tomcat-9.0.12/lib
   2. In /home/lib/dspace/apache-tomcat-9.0.12/conf/server.xml I added the
   following Resource

   <Resource name="jdbc/dspaceWeb"
                 factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
                 type="javax.sql.DataSource"
                 auth="Container"
                 username="*****"
                 password="******"
                 driverClassName="org.postgresql.Driver"
                 url="jdbc:postgresql://localhost:5432/dspace"
                 initialSize="5"
                 maxTotal="50"
                 maxIdle="15"
                 minIdle="5" />

   There are a couple of issues that confuse me:
   a) the official documentation about JNDI datasource examples [0] says "*This
   author has not had success here, although others have reported so.
   Clarification would be appreciated here."  *in the section about
   Postgres. In other words, we can't be sure this works?
   b) in the official documtation about JDBC connection pool it says that
   if you want to define a JDBC connection pool in the Apache Container (which
   I understand to be trying to do) you have to specify the factory attribute
   and set the value to org.apache.tomcat.jdbc.pool.DataSourceFactory [1]

   This is not done in the example (that the author hasn't had success
   with?) in a)
   3. Created a context.xml in /dspace/webapps/xmlui/META-INF/

   <Context docBase="/dspace/webapps/xmlui">
       <ResourceLink name="jdbc/dspace"
                     global="jdbc/dspaceWeb"
                     type="javax.sql.DataSource"
       />
   </Context>


When I start up Tomcat howere. I get this in the log:

INFO [org.springframework.jndi.JndiObjectFactoryBean] JNDI lookup failed -
returning specified default object instead:
javax.naming.NameNotFoundException: Name [jdbc/dspace] is not bound in this
Context. Unable to find [jdbc].

My understanding is that the webapp, DSpace, tried to look for a JNDI
object in the namespace "jdbc/dspace" and barring that, falls back to
instantiating it's own DataSource as a bean. See [4]

But I don't understand why the above doesn't work.

Thanks for your time

Sources:
[0] :
https://tomcat.apache.org/tomcat-9.0-doc/jndi-datasource-examples-howto.html#PostgreSQL
[1] :
https://tomcat.apache.org/tomcat-9.0-doc/jdbc-pool.html#Inside_the_Apache_Tomcat_Container
[2] :
https://wiki.lyrasis.org/display/DSDOC6x/Installing+DSpace#InstallingDSpace-Externaldatabaseconnectionpool
[3] :
http://dspace.2283337.n4.nabble.com/Notes-on-PostgreSQL-connection-pooling-with-a-Tomcat-JNDI-resource-td4687149.html
[4]:
https://github.com/DSpace/DSpace/blob/dspace-6_x/dspace/config/spring/api/core-hibernate.xml

Reply via email to