1

I have a question about deploying a springboot app. Is it possible to get the data source settings from tomcat context.xml resources instead of the application.properties file?

In this project, I already have a war deployed in tomcat and it uses the data source properties from context .xml of tomcat (it is maven project it and it uses hibernate to access the database).

I'd like to do the same thing but using springboot.

zszoubair
  • 13
  • 3
  • do you want to create a war file from your spring boot application or are you planning to use the embedded tomcat? if you are planning to create a war file then you should use the same config as you use now. – cool Apr 01 '18 at 21:40
  • yes i wanna create a war file so that it could get the datasource from the context xml of tomcat server , m just adding like a new module of an existing application – zszoubair Apr 01 '18 at 21:42
  • pls refer this link : https://www.journaldev.com/2597/spring-datasource-jndi-with-tomcat-example – Muthu Apr 02 '18 at 11:22
  • i need the configuration linked to spring data not normal JDBC :/ – zszoubair Apr 02 '18 at 11:56

1 Answers1

1

You can use the jndi name as you use now like this in spring boot:

spring.datasource.jndi-name=java:comp/env/jdbc/mydb

that part is the actual name

jdbc/mydb
cool
  • 1,746
  • 1
  • 14
  • 15
  • o i should add some a ressource or jndi like this in tomcat context xml and in application . properties i'll add the following properties : spring.datasource.jndi-name=java:comp/env/jdbc/mydb is that it ? – zszoubair Apr 01 '18 at 21:49
  • then you should use spring.datasource.jndi-name=java:comp/env/jdbc/TestDB in your application.properties – cool Apr 01 '18 at 21:50
  • Yes that is true – cool Apr 01 '18 at 23:56
  • exception : 2018-04-02 12:07:46.681 WARN 1440 --- [ost-startStop-1] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor': Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javax/el/ELManager – zszoubair Apr 02 '18 at 11:10
  • what do you think ? – zszoubair Apr 03 '18 at 12:32
  • https://stackoverflow.com/questions/45841464/java-lang-noclassdeffounderror-javax-el-elmanager – cool Apr 03 '18 at 12:48