On 04/09/2024 21:34, charliedidon...@gmail.com wrote:
Hello
Tomcat 10.1, Java 17, MySQL Connector 9.0
Not sure if this is a Tomcat Config issue or Spring MVC 6 issue
I am converting from Spring MVC 4 to 6 and have the following set up in
Tomcat 10.1
Context.xml
<Resource name="jdbc/CodereaperDB" auth="Container"
type="javax.sql.DataSource"
maxTotal="20" minIdle="1" initialSize="1"
testOnBorrow="true" testWhileIdle ="true"
username="reference" password="XXXXXXX"
driverClassName="com.mysql.cj.jdbc.Driver"
validationQuery="select 1"
url="jdbc:mysql://192.168.0.28:3306/reference_tables?allowPublicKeyRetrieval
=true&useSSL=false&autoReconnect=true&"/>
That looks reasonable.
Server.xml
<GlobalNamingResources>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users
-->
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
This resource link is unnecessary and may be causing problems. Resource
links are used in context.xml to expose resources defined in server.xml
to the web application. You have defined the resource directly in the
web application so there is no need for a resource link.
ResourceLink name="jdbc/CodereaperDB"
global="jdbc/CodereaperDB"
auth="Container"
type="javax.sql.DataSource" />
</GlobalNamingResources>
When I deploy my Spring MVC 6 app I get the following in the Tomcat logs
Enable debug logging for the JNDI lookup with:
org.apache.naming.level = ALL
in $CATALINA_BASE/conf/logging.properties
The full path to that DataSource should be:
java:comp/env/jdbc/CodereaperDB
Mark
Caused by: javax.naming.NameNotFoundException: Name [jdbc/jdbcCodereaperDB]
is not bound in this Context. Unable to find [jdbc].
at
org.apache.naming.NamingContext.lookup(NamingContext.java:520)
at
org.apache.naming.NamingContext.lookup(NamingContext.java:155)
at
org.apache.naming.SelectorContext.lookup(SelectorContext.java:144)
at
java.naming/javax.naming.InitialContext.lookup(InitialContext.java:409)
at
org.springframework.jndi.JndiTemplate.lambda$lookup$0(JndiTemplate.java:157)
at
org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:92)
at
org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:157)
at
org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:179)
at
org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:9
6)
at
org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:114
)
at
org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObject
FactoryBean.java:239)
at
org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObject
FactoryBean.java:225)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory
.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1853)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory
.initializeBean(AbstractAutowireCapableBeanFactory.java:1802)
... 88 more
Related cause:
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'dataSource' defined in class path resource
[atlas-dao-context.xml]: Name [jdbc/jdbcCodereaperDB] is not bound in this
Context. Unable to find [jdbc].
Should I still be using javax.sql.DataSource or should I use something else
in the Jakarta packages??
My Spring bean is below
<bean id="dataSource"
class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="jdbc/jdbcCodereaperDB"/>
</bean>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org