So I was curious if anyone has a pattern out there to solve this with a recent version of Spring Boot? My IT Department hosts their own Tomcat servers and prior to me switching over to Spring Boot we would create our own DataSource configuration class to get the proper database connection information from the servers Context.xml because IT managed their own database credentials and just gave us the JNDI path. Then when developing locally would use a local Context.XML to do the same thing with the same JNDI path but using my issued credentials. Can I do this with embedded tomcat so when I deploy to Dev and Production servers managed by IT that it will connect without me having to change anything? I am using application.yml file to configure spring=>datasource=>jndi-name.
Thanks
This is a perfect use case for Spring Profiles.
You can work with profiles in many ways. See this article for an overview. For your use case the following is probably sufficient.
application.properties
with the configuration for the JNDI datasource as normal.application-dev.properties
, and replace the datasource configuration with the configuration of your local datasource.spring.profiles.active=dev
This is essentially the comment of M. Deinum. So if you find it useful find some nice answer of him and give it an upvote. Shouldn't be difficult to find a good one.