SpringBoot yml how can I run two profiles at the same time - spring-boot

In my application yml, I have two profiles which I need to both run
spring:
profiles:
active:
awss3, #env#
application:
name: CONFIG-SERVICE
I need awss3 to be run, in what ever the env is. Is this possible ?

In my opinion, your requirements fits Profile Groups. This approach is preferable as it allows you to visually inform the developer which profiles are required for which environments.
https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.profiles.groups
Example:
spring:
profiles:
group:
production:
- "aws3"
- "prodmq"
Then you can start the application using:
--spring.profiles.active=production
to active the production, aws3 and prodmq profiles in one hit.
To clarify: The keyword production under group: is what you will use when you run your application as spring.profiles.active=production
Alternatively like you can simply add whatever profiles you want from the command line.
java -jar -Dspring.profiles.active=awss3,prodmq demo-0.0.1-SNAPSHOT.jar

yes, using properties:
// Use your dynamic profile
spring.profiles.active=#env#
// Include your default profile
spring.profiles.include=awss3
yaml:
spring:
profiles:
include: awss3
active:
#env#

Related

Spring profiles group

I decided to deal with the profiles and divide into groups
spring:
//Common settings
---
spring:
profiles:
group:
default:
- prod
- actuator
dev:
- dev
- actuatorDev
uat:
- uat
- actuatorUat
Why when I specify dev or uat.
The settings are loaded from the main block, then replaced from dev or uat. And on top is the actuator profile
And when I don't specify the profile at startup, in theory it's just default
This kind of magic doesn't happen
How to correctly implement general settings and then replace them depending on the default, dev, uat profile?
Please Test:
//...
spring:
profiles:
default: "prod,actuator" # when no profile*S* set [3.]
group: # ...according to [3.1] and [3.2]
dev:
- "dev"
- "actuatorDev"
uat:
- "uat"
- "actuatorUat"
Spring (current) Ref: Chap. 3 Profiles

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

Specifying multiple Spring active profiles in k8s deployment yml

I am having two active profiles in my module in Java.
I am trying to specify it in kubernetes like this:
env:
- name: spring_profiles_active
value: ["dev", "shop-module"]
Is the correct way to specify the two active configs?
Multiple active profiles can be configured in the below way:
application.properties
spring.profiles.active=dev,hsqldb
(or)
application.yml
spring:
profiles:
active: "dev,hsqldb"
how do you pass it while on command line ?? it will be supported surely if can be done via command line or you can do outside of kubernetes
try this link,
How can I specify the spring.profiles.active param with a value from an environment variable using fabric8 maven plugin?

spring boot - application yml for each developer

In my work the fields in application.yml are dynamics and each developer have another (dynamic) configuration. So, we have the general yml section, that relevant for all of us (and have updates from time to time) and the “private profile”
Like this:
spring:
profiles: default
configuration:
...
...
spring:
profiles: development1
configuration: ...
spring:
profiles: development2
configuration: ...
We have “small” problems with this (mistakes, conflicts, etc.) and we’re look for solution.
I think about separate yml file for each developer, such as:
spring:
profiles: development1
configuration:
yml-file: app_dev1.yml
spring:
profiles: development2
configuration:
yml-file: app_dev2.yml
but didn’t find how to do this…
Will be glad to know if it can be done? (or you have another way to separate the yml between us).
We do not want to set an application yaml with annotation (git issues again..), something like Environment Variables...
Spring boot by default loads application.yaml but in addition if you run with --spring.profiles.active=dev1 it will load file application-dev1.yaml
So you could create yaml file per developer + have some "common" configuration in application.yaml
With such an approach you won't need lines like:
spring:
profiles: dev1
... in any of the yaml files

Spring cloud config in local dev mode

Is it possible to control if the application requires spring-config-server based on profile.
I want to pick properties from resource/... in say local-dev profile and use cloud-config only with a profile where there would be a config-server running.
You can disable using config-server for a specific profile. Please try to define the properties in bootstrap.yml like below. Please note, we should configure these settings only in bootstrap.yml. Setting these properties in application.yml will not work. In this case, local profile will be running only with local profiles in /resources folder. In dev profile, properties from config-server will override properties from resources/ folder.
spring:
profiles: local
cloud:
config:
enabled: false
---
spring:
profiles: dev
cloud:
config:
uri: http://<your config server>

Resources