Getting datasource from tomcat context.xml instead of application.properties - java

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.

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

Related

How to read known_hosts file from "Resources" folder in a Spring Boot Application with Cloud Config Server and SSH enabled

I have a spring boot application which has Config Server enabled with #EnableConfigServer annotation.
The config server connects to a Git repository hosted on Bitbucket.org using SSH Access key.
Since the spring boot app is intended to be deployed to Amazon Web Services, I want to have my 'hosts' file for SSH included in the project. Spring has a property for this:
spring.cloud.config.server.git.known-hosts-file
The problem I am facing is the following: KnownHostsFileValidator (a class from spring config) tries to verify if the file exists with the following code:
new File(knownHostsFile).exists()
If I want to include my hosts file in the resources directory to be packaged in the jar, then this validation fails, since the file name I give for the known-hosts-file property is not pointing to the "resources" directory.
My question is: how should the property for known-hosts-file look like to actually point to a file in the resources directory when "new File(filePath)" is executed?

Spring Boot external Tomcat and external application.properties

i created a new spring boot application.
For development i use the default "appilcation.propperties" for my configuration.
But for production i want to have a external configuration file, because this application will run on multiple tomcats. So i want to have a "application.properties" on every tomcat.
EG:
"SERVER/TOMCAT1_ROOT/conf/application.propperties"
"SERVER/TOMCAT2_ROOT/conf/application.propperties"
Now i thought i can add this path dynamicly in my default "application.propperties":
spring.config.additional-location=file:${CATALINA_HOME}/conf/application.properties
But this line is not parsable. So is there any way to include a path dynamicly?

Specify spring config file from default config file

I'm building a war package which will be deployed into a web container using spring boot. And I want to put the spring boot config file outside the war file. My idea is to put the file location in System Property and specify it from spring boot's default config file in directory resources, something like this:
spring.config.additional-location: ${encryption.home}/
or
spring.config.location: ${encryption.home}/
But neither works, seems it doesn't load the external config file. How can I do this? Or whether there's another approach for me to put spring boot config file (not in classpath) outside a WAR file.

when deployed Spring Boot war in tomcat where should application.yml file should be placed?

When spring boot,mvc war file has been deployed in stand alone tomcat, application.yml is located at $CATALINA_HOME/webapps/demo/WEB-INF/classes/application.yml
Can I move the same to $CATALINA_HOME/conf/Catalina/localhost/dmo.yml ?
In general without using spring boot my configuration file will be located at $CATALINA_HOME/webapps/demo/META-INF/context.xml which can be moved to $CATALINA_HOME/conf/Catalina/localhost/demo.xml
Is the same is possible for application.yml also? Then How?
This will help while re-deploying my config file will be backed-up automatically.
You can change the default location for application.properties/yml files using spring.config.location and spring.config.name properties and their corresponding environment variables. The easiest way is to set the SPRING_CONFIG_LOCATION environment variable:
export SPRING_CONFIG_LOCATION=$CATALINA_HOME/conf/Catalina/localhost/dmo.yml
Check out spring boot documentation for more info on loading property files.

Migration of my application from Glassfish 2.1. to JBoss 7.1.3 -Related to user shared lib

Good day!
My application is running fine in Glass fish 2.1. It is .ear file. I am using more configuration file like xsl,xsd,apache log4j xml and some property files to my application. So I have created shared library in my disk say C:/SharedLib and put all my configuration files in this location. In glassfish I will give this location in my Application Server-->JVM settings-->path settings --> Classpath prefix --- C:/SharedLib
I will use all the property files,jar files and xsl,xsd from that location(C:/SharedLib. My application (.ear ) contains ejb and war file.
My question is how i can use same configuration in my Jboss 7.1.3? Is there any way without changing my code in my application .ear?

Categories