Prashant
Prashant

Reputation: 167

Environment specific application.properties in springboot Application

I'm trying to automate the process of deploying code using github and jenkins job to deploy my Springboot Application on AWS .

I want to know where should I place the application.properties file in case I m deploying a war file on Tomcat and don't want this file to be pushed onto github as it may contain some database credentials , not to be exposed.

Should I put separate application-prod.properties file in Tomcat (AWS) so that my war file will be independent of these properties ?

Upvotes: 1

Views: 2074

Answers (2)

Horsing
Horsing

Reputation: 1100

how about using spring-cloud-starter-config instead of local properties ?

If using spring-cloud-start-config, all configurations should be loaded from your config-center instead of reading them locally.

Even if you have multiple different environments, spring-cloud-starter-config could handle it with different profiles.

What's more, spring-cloud-starter-config could use local environment variables too.

By the way, the only local resource could be bootstrap.yml if you are using spring-cloud-starter-config.

Wish I can help you!

Upvotes: 1

Marco Tedone
Marco Tedone

Reputation: 602

See my answer here.

In a nutshell, you externalise the properties and then pass one or more profiles that will activate one or more Spring Configuration classes. Each Configuration class will load one or more property file. In your case, if you only have one environment, you can just create a configuration file for one profile.

Then, on your AWS instance, you will deploy the configuration file separately. At runtime, you will need to pass to your Spring Boot application the active profile(s). You can do this by passing the VM argument: -Dspring.profiles.active=[your-profile]

I'm completing the final lectures on an online course that shows how to create from scratch a Spring Boot website with Thymeleaf, Spring Security, Email and Data JPA, how to process credit card payments with Stripe and how to deploy to AWS. You can register your interest here.

Upvotes: 2

Related Questions