In Taurus is it possible to use an external properties file for specifying properties ?
I have read this but didn't find the solution.
My concern is that I have something like 40 properties in existing user.properties and don't want to move them in YAML file.
Directly no, however you can define the properties in a separate YAML or JSON file and include it into main YAML config like:
included-configs:
- properties.yml # the file containing your properties definitions
Related
Thorntail generator does not generate any project_defaults.yml file in project structure. No resources folder also seen.Should we manually place this file to configure project properties?
Note : I am new to thorntail.
Yes, you need to create a file project-defaults.yml inside src/main/resources.
Is there a way to override Spring's default file extension for the properties file? I know that you can change the name with the spring.config.name setting, and the location with the spring.config.location setting, but it still expects the file to have a filename extension of .properties. So far I have been unable to tell it to use a file like system.props as a properties file.
I have different files (yml & xml files) where I'm hardcoding the same folder path containing my configuration files. I want to parameterize this path, so I can be able to move my configuration and modifying my parameter only once.
My bootstrap.yml :
...
cloud:
config:
failFast: true
server:
bootstrap: true
prefix: /config
native:
search-locations: file:///C:/dev/workspace/application/config/{profile}
My application-dev.yml :
...
logging:
config: file:///C:/dev/workspace/application/config/{profile}/log4j2-dev.xml
My integration-config.xml :
<context:property-placeholder location="file:///C:/dev/workspace/application/config/${spring.profiles.active}/application-${spring.profiles.active}.properties" />
How can I achieve that ? What's the best practice in this case ? Or is it even good practice to parameterize the search-locations path for the Spring Config Server File System ?
First say I'm almost not use configuration file (yml properties xml...) directly in local-file-system(outside classpath) even for local test. And for spring-cloud-config what if you using remote location to contains config, question may different.
Second, did you using some project manager tool like maven or gradle? as maven is the default tool for spring-boot projects' build in my mind. And for maven there has plugin like Maven Resources Plugin to parameterize your config variable to pom.xml which can help you modifying parameter only once for all variable in one file in build step, and same as gradle.
For spring-cloud-config, it is possible to move your almost all configuration properties to it. Means that you can move your config properties from application-dev.yml and integration-config.xml to spring-cloud-config's config file which in your case is file:///C:/dev/workspace/application/config/{profile} and it will load as env variables in runtime for spring autoconfigure or which you can #Autowired to your Environment what if you want get it manually.
I have properties file with name : transactionexpiry.properties in my project's src/main/resources folder.
I am able to read the properties in the code with #PropertySource("classpath:/transactionexpiry.properties")
Now I wan't to add application scope and add environment specific config files as transactionexpiry-dev.properties, transactionexpiry-local.properties, etc
But the same works with application.properties, application-dev.properties, application-local.properties
Is there a way to make it work with my previous set-up?
If you are using spring profiles:
-Dspring.profiles.active=dev
Then you can call the properties file like:
#PropertySource("classpath:/transactionexpiry${spring.profiles.active}.properties")
I'd like to avoid cluttering the application.properties file with lots of things than, in my opinion, would be better in a separate file.
application.properties should be something like
#include module1.properties
#include module1.properties
...
###################################
######### Spring Misc #############
###################################
# Direct log to a log file
logging.file=/tmp/kmp-manager.log
#local listening port
server.port=8082
spring.profiles=nr_dev nr_testing production
spring.profiles.active=production
spring.datasource.platform=postgresql
java.security.egd=file:/dev/./urandom
Is this at all possibile?
If not, what would be a sane way to avoid cluttering?
Spring Boot Spring Boot 2.4 has added a feature for importing
We can now use spring.config.import=developer.properties to import other file. Check this blog post for more details
It's possible in YML file and the configuration are very simple
EXAMPLE:
To include properties of application-DATABASE.yml file in application.yml, use
spring:
profiles:
include: DATABASE
[EDIT - for 2.4.0 and above]
spring.profiles.group.prod=DATABASE
OR
Add the file name in application.properties
spring.config.import=classpath:application-DEV.yml,classpath:application-UDEV.yml,classpath:application-PRO.yml,classpath:application-SBA.yml
spring.config.import: file:${CLOUDJAVA_ROOT}/config/application.yaml
Imports are processed as they are discovered, and are treated as additional documents inserted immediately below the one that declares the import. Values from the imported file will take precedence over the file that triggered the import.
See spring-boot docs: Importing Additional Data