Spring Boot - ignore application.yml / bootstrap.yml inside .jar file - spring-boot

I have a spring cloud application using config server for fetching configuration. We are using Spring Boot 1.5.4 & Spring Cloud Dalston.SR2.
For deployment purposes we are providing external bootstrap.yml file and specifying its location with spring.cloud.bootstrap.location parameter.
We already had some struggle with the fact that, for couple of properties, service fell back to .jar's bootstrap.yml / application.yml
The only way I could find to solve that, was changing name of external configuration files with spring.config.name and spring.cloud.bootstrap.name. Then, the original names from .jar won't be matched and taken under consideration.
Is there are other way to tackle that?

You could solve that by upgrading to Spring Boot 2.x because they fixed the behavior of spring.config.location (see https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.0-Migration-Guide#configuration-location) which also affects spring.cloud.bootstrap.location in the same way
See also that question Different behavior of spring.cloud.bootstrap.location since Spring Boot 2

Related

Spring Boot Actuator refresh not working for Spring Cloud updates to ${spring.application.name}.properties files

I have several Spring Boot REST services that pull in properties from a Spring Cloud Config server. Let's say the application is called ApplicationName. In that case, the properties files are called ApplicationName.properties, ApplicationName-test.properties, etc. If I update one of those files and trigger the /actuator/refresh endpoint, it doesn't update the properties in the service. It just returns:
[
"config.client.version"
]
indicating it detected a change, but it did not detect the specific value that changed.
Previously, I used Spring Boot 2.3.x and this all worked perfectly. Once I updated to Spring Boot 2.6.x, it stopped working. I just updated to Spring Boot 2.7.1 and it's still not working.
However, if I have properties in a file called application.properties hosted on the same Spring Cloud Config server and I update that one, the refresh endpoint works fine.
I have the Config class annotated with #RefreshScope.
I have the following in my application.yml:
management:
endpoints:
web:
exposure:
include: refresh
endpoint:
refresh:
enabled: true
I have the following in the bootstrap file:
spring.cloud.config.uri=https://spring-cloud-config.domain.com
spring.cloud.config.name=${spring.application.name}
I'm using Spring Boot version 2.7.1 and Spring Cloud Version 2021.0.3.
It seems like there's a setting I'm missing to tell the refresh actuator to check the ${spring.application.name}.properties file in addition to the default application.properties file. Any idea what that setting might be?
Update:
I tried putting the config files in a subdirectory in Bitbucket where the Spring Cloud Config server pulls from. The subdirectory is the name of the application, and the config files inside are named application.properties. The application reads them in fine, but the refresh doesn't work for those either. It seems to only work for files named application.properties that reside in the root directory.
It looks like the following no longer works in the bootstrap.properties file:
spring.cloud.config.name=${spring.application.name}
It allows the properties to load when the service starts, but it does not allow the properties to be refreshed. I was able to get it working by specifying the actual application name:
spring.cloud.config.name=MyApplicationName

Spring cloud config server not honoring logging.file property and not logging external file

I'm using spring-boot-starter 2.3.3.RELEASE version. I'm running my spring cloud configuration server in native profile (looking for configuration files in file system). I added
logging.file = /var/log/config.log in application.properties file. But my application is not logging logs to this file.(All other microservices are logging to this location). Am I missing any additional settings for Spring cloud config server? Thank you so much for your help.
In the spring boot 2.3.3 RELEASE documentation the logging properties that specify where the location should be is indicated using the property:
logging.file.path={path}
The documentation:
https://docs.spring.io/spring-boot/docs/2.3.3.RELEASE/reference/htmlsingle/#boot-features-logging-file-output
This modification from logging.path to logging.file.path appears as a deprecation in Spring Boot 2.2:
https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.2-Release-Notes#deprecations-in-spring-boot-22
One way to do it with spring-boot application is, setting it from command line argument as default it will dump every thing on console.
logging.file=logs/test.log
Old school but far effective, save path in application.properties
logging.file=logs/test.log

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.

How to set threshold of SlowQueryReport interceptor of Tomcat in Spring Boot properties

We need to configure SlowQueryReport Tomcat interceptor in our Spring boot application, specifically threshold value in properties files. Couldn't find anything on the web. Any help?
We used the old syntax (see below, note the given threshold) in the configuration file and it worked:
spring.datasource:
tomcat.jdbc-interceptors: org.apache.tomcat.jdbc.pool.interceptor.SlowQueryReport(threshold=10);any.other.tomcat.Interceptor

How to use Spring Boot externalized configuration at Cloud Foundry

For externalizing configuration in a spring Boot application, I follow the standard way of having an application.properties in the classpath. And then, in the production environment, I put another application.properties beside the JAR which overrides the earlier one. This way, I can have, say, a name property having different values in development and production environments.
Liked to know how to do the same thing when deploying to Cloud Foundry.
You can simply put the properties to override as environment variables (replace dots with underscores, and Boot will match everything up).
You might also want to have a look into the Spring Cloud Config Spring project within Spring Cloud:
"Centralized external configuration management backed by a git repository. The configuration resources map directly to Spring Environment but could be used by non-Spring applications if desired."

Resources