spring boot 3 profile property values getting overridden in boostrap.yaml - spring

Recently trying to upgrade to Spring Boot 3, but facing property issue.
My bootstrap yml looks like below,
When I run with profile dev, the configserver url is always getting connected to qa, basically whichever is declared last.
This is working fine in 2.7.X version of spring, but not in spring boot 3
spring:
application:
name: appname
profiles:
active: ${spring.profiles.active}
include:
- global-defaults
group:
dev:
- config-server-dev
- cloud-config-dev
qa:
- config-server-qa
- cloud-config-qa
---
spring:
config:
activate:
on-profile: config-server-dev
cloud:
config:
enabled: true
uri: http://urltoconfigserverdev
label: master
---
spring:
config:
activate:
on-profile: config-server-qa
cloud:
config:
enabled: true
uri: http://urltoconfigserverqa
label: master
---
But the same is working fine if add the property migration pom dependency. which is not suggested for higher environments.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-properties-migrator</artifactId>
<scope>runtime</scope>
</dependency>

If adding the properties migrator fixes the problem, it's likely that your configuration file is using a configuration property name that's been removed after deprecation. I'm not seeing anything specific to Spring Boot in the changelog, maybe this is due to a change in spring cloud config? The properties migrator should print WARN logs during startup, looking at those should tell you what needs fixing.

Related

How can I activate Profile in Spring Boot YAML?

I have below application YAML of my Spring Boot (2.4.5) application with two profiles.
spring:
profiles: dev
spring:
profiles: prod
Now when I pass the arguments -Dspring.profiles.active=dev, it actually doesn't pickup the profile. Is there any changes in profile has been made recently.
When I activate the profile, like below it works
spring:
profiles:
active: dev
But as per the env profile can be different. I don't want to hard code the profile
You should use the following instead in your application.yml:
spring
config:
activate:
on-profile: dev
---
spring
config:
activate:
on-profile: prod

How can use ConfigDataEnvironmentPostProcessor and spring.profiles.group?

I'm using Spring Boot 2.4.2 and tried to use spring.profiles.group in my property files like:
application.yaml
spring:
profiles:
group:
local: core
application-core.yaml
---
spring:
config:
activate:
on-profile: local
...
but the "group" property is not found.
As I checked, it is using deprecated ConfigFileApplicationListener instead of ConfigDataEnvironmentPostProcessor.
Why it uses legacy spring profile processing even though version of spring is upper 2.4.0?
application-core.yaml doesn't require the following:
---
spring:
config:
activate:
on-profile: local
This is what is needed:
application.yaml:
spring:
profiles:
group:
local: core
application-core.yaml
...

Spring Boot 2.2.2 - Prometheus not working in Actuator

I've upgraded my Spring Boot application to the latest 2.2.2 Boot version. Since then, I only have a metrics endpoint but no Prometheus.
My build.gradle.kts file has org.springframework.boot:spring-boot-starter-actuator as dependency, I also added io.micrometer:micrometer-registry-prometheus as the reference suggests (Prometheus endpoint).
My application.yml looks like the following:
management:
server:
port: 9000
endpoints:
web:
exposure:
include: health, shutdown, prometheus
endpoint:
shutdown:
enabled: true
Can someone guide me to the right direction?
Edit: It was working in Spring Boot 2.2.0. This is the link to download an identical project: link
Edit 2: I can verify that it works with 2.2.1 as well.
I followed your setup, I created a project from this project loaded Spring Boot 2.2.2.RELEASE, I added the following dependency for Prometheus
implementation("io.micrometer:micrometer-registry-prometheus")
Also I added the following configuration in application.yml
management:
server:
port: 9000
endpoints:
web:
exposure:
include: health, shutdown, prometheus
endpoint:
shutdown:
enabled: true
When the application starts you will see the following info which shows you that 3 endpoints are exposed (health, shutdown and prometheus).
2020-01-05 23:48:19.489 INFO 7700 --- [ main] o.s.b.a.e.web.EndpointLinksResolver : Exposing 3 endpoint(s) beneath base path '/actuator'
And used Postman for method GET this endpoint http://localhost:9000/actuator/prometheus and it works well. I created a repository by following these steps here So please let me know what error is displayed, or what happens when you don't get the expected result so that I can help and edit this answer.
Add below maven dependency for prometheus
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<scope>runtime</scope>
</dependency>
In application.yml, add the below configuration
management:
endpoints:
web:
exposure:
include: "*"
endpoint:
health:
show-components: always
show-details: always
probes:
enabled: true
Now you could see the below message when you restart the server
Exposing 15 endpoint(s) beneath base path '/actuator'
Access the prometheus url: http://localhost:8080/actuator/prometheus

Spring Config uri

I have configured bootstrap.yml for spring config
spring:
application:
name: cce-auth
cloud:
config:
uri: http://temp.com:8888
It works fine but I need URI value Dynamically, for example if I will publish this .war in test environment this URL must be http://test-temp.com:8888.
So for this I have solution create config.txt file in server and using I/O Stream reed/write this string to bootstrap.yml.
But problem is loading, spring loads http://localhost:8888 before I'm writing in bootstrap.yml.
So my reason is to create dynamically URI for config server.
DO you have any idea?
Define active_profile in bootstrap.yml file
spring:
profiles:
active: ${activatedProperties}
Then create bootstrap-${activatedProperties}.yml for each environment, etc..bootstrap-dev.yml, bootstrap-pre.yml, bootstrap-prod.yml
For example:
spring:
application:
name: servicename_prod
cloud:
config:
uri: https://admin:123456#test.com:8888
server:
port: 8443
add plugin to pom.xml file :
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
When run java, define environment on it: for example, run with prod environment.
java -Dserver.port=8443 -Dspring.profiles.active=prod -jar ....

Spring Boot + Spring Cloud Config - How to add more profiles from the Git external configuration

I have this configuration in a spring boot application:
spring:
application:
name: my-app
profiles:
active: ${ENVIRONMENT}
cloud:
config:
uri: http://localhost:8888
My config server reads the following files:
my-app-dev.yaml
prop: dev property
my-app-pro.yaml
prop: pro property.
I launch the spring boot app setting -DENVIRONMENT=dev, loading correctly the dev external Git properties.
When I inject the Environment in let's say a controller and do env.getActiveProfiles() I get "dev" as expected.
I would like to add more profiles from the git configuration. For instance:
my-app-dev.yaml
prop: dev property
spring:
active:
profiles: dev,business1
my-app-pro.yaml
prop: dev property
spring:
active:
profiles: pro,business2
So that env.getActiveProfiles() returns ["dev","business1"]. However what it returns is the initial "dev".
How could this be done?
UPDATE:
As suggested by Dave Syer I tried using spring.profiles.include in the Git files but the new profiles aren't added to the Environment:
my-app-dev.yaml
prop: dev property
spring:
profiles:
include: business1
my-app-pro.yaml
prop: dev property
spring:
profiles:
include: business2
environment.getActiveProfiles() ---> "dev"
Update your spring-boot to 1.5.4.
I tested the same case on my Mac, I found that spring with different version behaves different.
When I'm using Spring Boot 1.3.8.RELEASE with Spring Cloud Brixton.SR7, I got the [dev] profile as active profile(also with Spring Boot 1.4.5.RELEASE)
When I'm using Spring Boot 1.5.4.RELEASE with Spring Cloud Dalston.SR1, I got the
[business1, dev] profile as active profile
So I believe it is a bug in Spring Boot 1.3.x and 1.4.x

Resources