How spring boot application knows in which environment code is running? - spring

How spring boot application knows where code is running??
local/dev environment
test environment
stage environment
prod environment
is there a way where spring boot app automatically pulls configurations from env specific file based on current environment of running app?

It doesn't know if you don't configuration.
Please read them:
https://www.baeldung.com/spring-boot-properties-env-variables
https://www.baeldung.com/spring-profiles
https://www.baeldung.com/spring-conditionalonproperty

Related

What is value of Docker over Gradle/Maven in Spring Boot Application

Every Tutorial/Guide that I have referred has explained how to build a spring boot application with docker. All those blogs have the same explanation as to why use docker for spring boot application, and it goes something like this
"A container is a standardized unit of software that assembles code, runtime, dependencies, settings, and initialization in a single package that you can run reliably from one computing environment to another."
Wasn't Maven/Gradle built for managing the dependencies? How is Docker responsible to assemble code? As far as I know, Spring boot creates a Fat Jar which runs its own embedded container with the specified JRE. The settings (I understand it as config) is taken from the env file.
Why would one containerize the application? What pain point is docker solving and if possible explain with an example.
Thanks in advance.

Passing configuration from yaml file to spring boot application without rebuilding it

How to pass configuration through yaml file to a running spring boot application so that there is no need of rebuilding the application and changes are reflected while the application is runnig?
I think this can help you:
How to hot-reload properties in Java EE and Spring Boot?
Take a look at Spring Boot Cloud Config. It allows you to manage your config files centralized and has the ability to push new configurations to the connected applications.

Spring Boot Micro-service fails Kerberos Authentication when deployed on Pivotal Cloud Foundry Platform

We have developed a Spring Boot Application to query data from Hbase on HDP 2.5.
The application works fine when we run it on our local windows machines as it is able to find the jaas.conf & krb5.conf file which have been kept under resources folder of the application and we have provided them as system properties in our code as e.g.
System.setProperties("javax.security.auth.useSubjectCredsOnly","false");
System.setProperty("java.security.krb5.conf","D:\\host\\workspace\\projectname\\src\\main\\resources\\krb5.conf");
However when we deploy in PCF it is unable to read those file which are set as system properties.
Question
What is the way to set environment variables in PCF ?
How do we place files in PCF so that they are available to the classpath of an application ?
You can specify an environment variable in your deployment manifest file.
Here are the details.
This is assuming your jar file was packaged with krb5.conf file.
The other option is to use Config Server. Here is an introduction on Spring Cloud Config

Spring Boot environment aware log4j properties

I try to use environment aware log4j properties files in Spring Boot application, for example, log4j.properties is used for development and log4j-uat.properties for UAT environment as showed in picture.
following Extern log4.properties file with Spring Boot, I added logging.config=log4j-uat.properties to application-uat.properties and get exception said cannot find that properties file.
following https://github.com/spring-projects/spring-boot/issues/1348, I added parameter when starting the application as java -jar logger-server.jar --spring.profiles.active=uat -Dlogging.config=classpath:log4j-uat.properties. However, it seems that the uat log4j properties is always overwritten by the default log4j properties.
Could anyone please advise me how to make Spring Boot pick up the log4j properties files for different environments?
Thanks,
Sean

How to set Spring active profile while running in WebLogic

How can I specify spring active profile while running spring boot application (as a war) in WebLogic? How to pass different -Dspring.profiles.active JVM arguments for different application deployed?
All suggestions welcome!
Thanks,
They are different ways to specify a profile in spring boot.
In your case, the better way is to add the property spring.profiles.active inside the application.properties, to avoid pasing it as argument when you launch the apps.
I hope my response help you.
Good luck

Resources