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/
Related
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.
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.
My config server is running on localhost:8888 but when i try to fetch configs from my config server ,its shows this error
Config data location 'configserver:http://localhost:8888/' does not exist
Action:
Check that the value 'configserver:http://localhost:8888/' at class path resource
[application.properties] - 2:22 is correct, or prefix it with 'optional:'
my other microservice has this application.properties
spring.application.name=limits-service
spring.config.import=configserver:http://localhost:8888/
spring.profiles.active=dev
This worked for me after removing text configserver from
spring.config.import properties
Before
spring.config.import=configserver:http://localhost:8888/
After
spring.config.import=http://localhost:8888/
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
I have use springboot to creat a project.
when I make yml file at src/main/resources/config or src/main/resources , I cant set :
spring:
profiles:
include:
- 'scheduling'
- 'yml'
in application.yml to appoint file file path,
and use #Value("${importance_info.message.notice}") to get the appointed value from
src/main/resources/config/application-scheduling.yml
but if I create yml not in the src/main/resources/config or src/main/resources, I can't get appointted value from it.
when I use #PropertySource(value = {"classpath:config/sub/sub-scheduling.yml"}), still can't get appointted.
Please tell me , how to make config or code to get appointed value from yml file in that file.