What is the difference between setting profile in quarkus with smallrye.config.profile or quarkus.profile - quarkus

In quarkus the config is stored inside an application.properties file.
You can have multiple application-{profile}.properties files. {profile} is the name of the profile you want it to be.
When started with java -jar <pathToJar> -Dquarkus.profile=PROFILE_ONE the file application-PROFILEONE.properties is used. During startup of the app you can read that quarkus is using the PROFILE_ONE profile.
When started with java -jar <pathToJar> -Dsmallrye.config.profile=PROFILE_ONE the file application-PROFILEONE.properties is used. During startup of the app you can read that quarkus is using the PROD profile.
What exactly is the difference between both? Is it better to use smallrye.config.profile so that quarkus is still using the PROD profile? Is the PROD profile faster?
Thanks!

That is actually a bug. Internally, both use the same profile, but the log is reporting a different one when you use smallrye.config.profile, because it is only checking for quarkus.profile and then it defaults to prod (later in the code the actual profile is checked and used the correct one).
The message needs to be fixed. I'll look into it.

Related

How configs pick ENV value

We have a config folder structure in apps like this:
config
config.author.test
config.author.stage
These have config.runmode.env values
I wanted to know from where It picks the "env" value.
I thought it is coming from runmodes. but in the instances, stage or test is nowhere.
Can anyone please help me know where does the AEM configs picks the value or where do we define those env value. Is it in some OSGi configuration or from where.
If you are not using the AEM runtime for the AEM Cloud SDK, then the run modes can be set in other ways as well apart from the sling.properties file. So depending on how you are starting your AEM server check if the run modes have been specified using the other options.
If you are using the AEM runtime from the cloud SDK, then check if the Jar file is named as shown in the Quickstart jar startup modes.

How we can organize different config profiles to use Quarkus profile in application.properties

I have different profiles based on environment wise and needs to load it. How i can achieve and also how to pass program arguments for Quarkus main application to take dev profile(spring.config.location=classpath:/config/dev/application.yml)
Is there a way to load databse configuration while starting #QuarkusMain. I have configured all the database configurations into one class and how this class can be load in main. Please suggest on this.
Quarkus 1.13 (and later), supports profile aware application.properties. Just name your file application-{profile}.properties and activate it with -Dquarkus.profile={profile}
If you want to load specific files, you can also use quarkus.config.locations. This is backed by SmallRye Config. Please check additional documentation here: https://smallrye.io/docs/smallrye-config/main/config/config.html

Spring Boot application profiles

I understand there's multiple ways of handling application property files and profiles in Spring Boot and I've seen multiple questions and answers on how to handle each but I'm trying to find the "best" way of handling it for a new project, if there is one.
The application is hosted in Weblogic 12c on production/pre-prod (with a jndi database connection) and ran locally in tomcat (with hardcoded database details) for development. I'd like it so that when the project is built via gradle and deployed to production it uses the jndi properties file and when ran locally it defaults to the hardcoded datasource with minimal changes required.
src/main/resources/application.properties
# DEV
spring.datasource.url=
spring.datasource.username=
spring.datasource.password=
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
# DEV
# PROD
# spring.datasource.jndi-name=
# spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
# PROD
From my understanding the recommended way is to externalize the property files and place the required one in a config directory alongside the WAR file for any differing config which is then automatically picked up and used?
You should consider creating multiple profiles. This means: Either multiple properties-Files, or multiple profiles in one file:
See https://docs.spring.io/spring-boot/docs/current/reference/html/howto-properties-and-configuration.html
I would recommend to use multiple application-ENV.properties, e.g.
application-prod.properties and application-preprod.properties.
There is always one active profile and settings from the application.properties (without any profile suffix) are used as default values if not overwritten in a specific profile-file.
Depdending on your environment (local, prod etc.) you should set an environment variable (start the java-process/application server with that environment variable), e.g.:
SPRING_PROFILES_ACTIVE=prod
On your local machine you would set:
SPRING_PROFILES_ACTIVE=dev
With this variable you can control, which profile is currently active.
Also consider integrating the active profile into you Continious Integration/Deployment settings.
Please note that putting plain text passwords hardcoded into committed files is not a good idea. Consider using jasypt or a spring cloud config server for your prod database configuraiton or use any mechanism that your cloud provider provides to you if you use any. Microsoft Azure for example provides a KeyVault for sensitive data.
https://cloud.spring.io/spring-cloud-config/multi/multi_spring-cloud-config.html
http://www.jasypt.org/
If you use gradle good solution is to set application.properties and test.properties files and put into them properties for prod and preprod respectively.
Then run application with different vm arguments: -Dspring.profiles.active=test for test.properties and without arguments for application.properties
Use gradle instruments and configure them once for test and prod. For example: gradle bootWar configure without vm arguments, gradle bootWarTest with vm arguments -Dspring.profiles.active=test. Save once you configs and you will create war for different environments only selecting between two buttons in gradle.

spring boot application properties based on spring profiles

Hi I want my spring boot web project to be deployed both on development and production environment and it should be run on specific profile based setting.
I googled on how to do that, and first of all that I have searched is defining application-{profile name}.properties properly in the src/main/resources classpath.
Now the problem is how to set profiles.
Since I am working on tomcat 8 in linux, there should be some configuration but I don't know how to do that.
and I am also curious that when my project is packaged as war file, java -jar {filename} -Dspring.active.profile=blahblah will not be work, but I think there is an alternative way.
plus, is there an way to set profile on tomcat 8 in Windows 10 ?
Thanks you
First:
I will recommend get rid of dedicated tomcat server and use embedded tomcat, jetty etc. Build your web apps as jar files and just run them. (of course if you don't have any limitations)
Second: You can do this either system property or env variable.
If you go with system property (order is important)
java -Dspring.profiles.active=blahblah -jar {filename}
If you go with env variable you need specify
SPRING_PROFILES_ACTIVE=blahblah

Environment specific properties from user home in springboot

I am working on a spring boot application in which i have to set Environment specific properties from user home folder.
i dig Google for the same & found we can put different properties file (dev, test, production) under resources and then we have to tell spring boot which environment we want to use using spring.profiles.active=dev OR prod.
however, my requirement is quite different. i will put a file in user home in my system & want to read properties form that file. how can i do that, need guidance.
Helping hands will be highly appreciated.
From the Spring Boot docs:
You can also refer to an explicit location using the spring.config.location environment property (comma-separated list of directory locations, or file paths).
As the docs go on to state, this must be specified on the command line or as an environment variable.
$ java -jar myproject.jar --spring.config.location=classpath:/default.properties,classpath:/override.properties
We explain that use case in a Devoxx presentation using EnvironmentPostProcessor, please refer to this section of the presentation for more details. You can also find the code sample online.
Well, it seems in your case you dont need environment variable. For production server your property file will be staying in and in staging machine it is also staying at same place. So where ever you deploy it will pick from . IMO you don't need to set environment, you just have to point property file to
Now to define this path you have 2 ways..
- You can put static path in your code
- You can set environment variable like Property_Path and read it in spring boot application..
However If you want to go one step ahead, you can use spring cloud configuration manager, by passing application+profile name to it, CM can fetch property file from directly from git or file system for you ...

Resources