Right now i have application.yml with
smallrye:
config:
profile: prod, postgres
But i want to do something like it
profiles:
active:
- ${APP_PROFILE:prod}
- ${APP_DATABASE_PROFILE:postgres}
How can i do this in quarkus?
You can set the active profile with the environment variable QUARKUS_PROFILE=PROFILE_NAME or via a system property with -Dquarkus.profile=PROFILE_NAME. You can also specify multiple profiles in these formats separated by commas.
Related
I have basic idea how spring profile works. But here in this file this - i am not able to get it. And current Application.yml file mentioning the three profile which one will get active and when that i need to know as well. Below is the Application.yml file content.
spring:
application:
name:
profiles:
active:
-default
-local
-swaggerinfo
Note: i have three config files present in my resources. Also if i want to look another config file
then spring use the naming convention like Application-<Name>.extension . so - is already get added for the new config file then why we explicitly need
to put another one in our application.yml file under spring.profile.active.
Below are the names of the three config files present under the resources folder.
application.yml
application-local.yml
bootstrap-default.yml
But here in this file this - i am not able to get it. spring use the
naming convention like Application-.extension . so - is already
get added for the new config file then why we explicitly need to put
another one in our application.yml file under spring.profile.active
spring:
application:
name:
profiles:
active:
-default
-local
-swaggerinfo
The declaration of profiles are incorrect. You must either put space or should not use (-) at all.
spring:
profiles:
active:
- default
- local
- swaggerinfo
The Spring also supports the following way of declarations.
spring:
profiles:
active: default,local,swaggerinfo
or
spring:
profiles:
active:
default
local
swaggerinfo
Here default refers to application.properties file not bootstrap-default.properties. Also, You don't need to specify the default profile. Spring automatically use application.properties as default one. So, in your case it's appropriate to go with local and swaggerinfo.
current Aplication.yml file mentioning the three profile which one
will get active and when that i need to know as well.
Let's talk about the following declaration.
spring:
profiles:
active:
- local
- swaggerinfo
Both local and swaggerinfo profiles will be active for props loading. So,which means that all the three files (application.yml by default) will be consumed by spring.
Let's talk about the order.
The order in the above case would be
application -> application-local -> application-swaggerinfo
Note:
Assume that you've mentioned the same prop in all the three files then in that case the precedence will be given as per the order highlighted above i.e prop mentioned in the application-swaggerinfo will override the ones available in the other twos.
this is my spring datasource config
spring:
datasource:
driver-class-name: org.mariadb.jdbc.Driver
url: ex.com
username: exId
password: exPw
and we know we can use os environment variable for spring datasource config like this
# export SPRING_DARASOURCE_URL=ex.com
But we can not export SPRING_DARASOURCE_DRIVER-CLASS-NAME because of '-' like this
# export SPRING_DARASOURCE_DRIVER-CLASS-NAME=org.mariadb.jdbc.Driver
So if i wanna get spring.datasource.driver-class-name via os environment variable,
what i have to do?
In most cases, any punctuation like those hyphens can be converted to underscores for the system environment variable, e.g. SPRING_DATASOURCE_DRIVER_CLASS_NAME. In some earlier versions of Spring this wasn't exactly standardized yet and some properties might drop the hyphens entirely, e.g. SPRING_DATASOURCE_DRIVERCLASSNAME.
Another approach: set the system env var, JAVA_TOOL_OPTIONS, with any desired Java/JVM options like:
JAVA_TOOL_OPTIONS=-server -Xmx1g -Dspring.datasource.driver-class-name=com.mysql.jdbc.Driver
I have an internal application.yml that specifies common properties and the profile:
spring.profiles.active: dev
spring.config.location: 'C:\externalConf\'
spring.application.name: myAppName
myproperty: aprop
Then I put my application-dev.yml in C:\externalConf\ but it seems it is not read.
Where is the problem?
You should pass config folder location like this:
spring.config.location=file:///C:externalConf/
info:
app:
env-active: dev
spring:
profiles:
active: ${info.app.env-active}
In my case, I want to use placeholder for setting spring.profiles.active. in my springboot application (application.yml), but when I start the project, the log is showing like blow.
The following profiles are active: dev,${info.app.env-active}
The real property is truly resolved, but the placeholder is still exists. Is that an bugs?
I'm wondering if there's a nice clean way to set logging location based on OS just using the application.properties file in Spring Boot?
For instance is it possible to use a regex matcher on ${os.name} or would I just need to go ahead and create a groovy script or something?
My ideal solution is something like
logging:
file: ${os.name}.test(/*window*/gi) ? C:/ProgramData/Logs/ : /var/log/
You can take advantage of spring profiles and pick configurations according to the -Dspring.profile.active=some_profile system property or SPRING_PROFILES_ACTIVE=some_profile env variable.
Yaml file could be
# a safe default relative to app root
logging:
file: logs
----
spring:
profiles: nix
logging:
file: /var/log/myapp
----
spring:
profiles: win
logging:
file: C:/ProgramData/Logs/
App is executed as
java -Dspring.profile.active=nix <more opts> MyAppMain
or also:
SPRING_PROFILES_ACTIVE=nix java <more opts> MyAppMAin