In spring, what's the difference between putting a property in jvm properties and bootstrap.yml? - spring

I know bootstrap properties are used in the bootstrapping phase before the application yml is loaded as per What is the difference between putting a property on application.yml or bootstrap.yml in spring boot?
However, I don't understand how adding a property using jvm options or system properties relates to these phases.

Related

Spring boot is not loading profile specific yaml or properties if set on EnvironmentPostProcessor

Spring boot is not loading profile specific yaml or properties if set on EnvironmentPostProcessor.
Please help on how to properly initialize this profile.

What are the different approaches to configure application.properties file in spring boot

One way is to directly edit appliaction.properties file in any editor and write the contents.
Is there any other external approach to do the same because in one of my project, I am unable to find anything in application.properties file when I open it in editor but when I run the application I get some information out of application.properties file.
The properties may be configured in many different standard ways with SpringBoot. I think the best way to identify where your parameters are is to list the locations given in the SpringBoot configuration documentation and check if your parameters are here.
EDIT List the locations :
Devtools global settings properties on your home directory (~/.spring-boot-devtools.properties when devtools is active).
#TestPropertySource annotations on your tests.
properties attribute on your tests. Available on #SpringBootTest and the test annotations for testing a particular slice of your application.
Command line arguments.
Properties from SPRING_APPLICATION_JSON (inline JSON embedded in an environment variable or system property).
ServletConfig init parameters.
ServletContext init parameters.
JNDI attributes from java:comp/env.
Java System properties (System.getProperties()).
OS environment variables.
A RandomValuePropertySource that has properties only in random.*.
Profile-specific application properties outside of your packaged jar (application-{profile}.properties and YAML variants).
Profile-specific application properties packaged inside your jar (application-{profile}.properties and YAML variants).
Application properties outside of your packaged jar (application.properties and YAML variants).
Application properties packaged inside your jar (application.properties and YAML variants).
#PropertySource annotations on your #Configuration classes.
Default properties (specified by setting SpringApplication.setDefaultProperties).

How -Dlogging.level JVM argument is handled in spring boot, spring cloud

I have a spring cloud application, which under the covers uses spring boot.
In the bootstrap phase of the app I am using some classes from the apache commons config library under: org.apache.commons.configuration
My application is started with this flag per the spring docs:
-Dlogging.level.org.apache.commons.configuration=INFO
Despite this, i am still getting DEBUG level logs emitted during the bootstrap phase of spring....
I am lost as to how to properly specify the log level of INFO specified for the bootstrap phase of spring boot.
Ensure you are not setting debug=true in application properties or not passing --debug flag to the application.
In application.properties set:
debug=false
The configuration of spring boot has a specific order, so probably somewhere in the application or bootstrap configuration files the logging level is configured to DEBUG.
Source:
https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html

Loading spring application-*.properties

I was wondering if there is a way to dynamically reference keys in multiple application-*.properties files in a spring application. The challenge I have is the property file names can be different for each app. I have tried various combinations of spring.config.location, spring.config.name, used ClassPathResource but no luck
For e.g. in src/main/resources I might have for application A application.properties, application-system-X.properties, application-system-Y.properties
For e.g. in src/main/resources I might have for application B, application.properties, application-system-P.properties, application-system-Q.properties
I am not sure whether I understand you problem correctly. But in Spring Boot you can dynamically use different application-*.properties by using profiles.
These profile-specific application properties can live inside and outside of your packaged jar (application-{profile}.properties and YAML variants).
I can also recommend to read the documentation on externalising your configuration with Spring Boot.

Spring boot datasource specific properties for embedded jetty server

I have spring boot application and it's basically a gradle project, so, I have below dependency added in my gradle file:
org.springframework.boot:spring-boot-gradle-plugin:1.5.1.RELEASE
Application gets deployed in embedded jetty server. I have following set of properties in application.properties for db connection polling:
spring.datasource.driver-class-name
spring.datasource.max-active
spring.datasource.max-idle
spring.datasource.min-idle
spring.datasource.validation-query
spring.datasource.name
I was referring to below two links:
https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-1.4-Configuration-Changelog
https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-1.5-Configuration-Changelog
I came to know that some of the datasource properties which used in application.properties file in my application are removed starting sprint boot version 1.4 but issue they haven't mentioned what are the new properties to use. Like for tomcat server they have provided all set of properties but not for jetty server. I am facing some db related errors like 'too many connections' after my application run for sometime, my assumption is that datasource props I am currently using are not correct and should be replaced with correct values, but unfortunately I am unable to find correct property names.
Jetty doesn't have its own Pooling DataSource implementation. You can include HikariCP in your project and customise using the spring.datasource.hikari.* properties. With each property matching the bean properties that can be set on Hikari's datasource implementation.

Resources