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&amp;useSSL=false&amp;autoReconnect=true&amp;"/>     

 

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" />

        

   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

 

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>

 

 

Reply via email to