How to specify external YAML configuration file for springboot

dweeb :

I'm trying to pass in a value to be autowired from a custom configuration file in Spring boot. Below are code snippets:

Spring class

@Configuration
public class MyConfig {

    @Value("${BOOTSTRAP_SERVERS}")
    private String bootstrapServers;

myfile.yaml

BOOTSTRAP_SERVERS: 
  10.0.0.12:9092

Execution command

java  -jar app.jar --spring.config.location=/file/path/myfile.yaml

However when I type the above command I'm getting this error:

java.lang.IllegalArgumentException: Could not resolve placeholder 'BOOTSTRAP_SERVERS' in value "${BOOTSTRAP_SERVERS}"

What am I missing here in order to get this to work? I intend to mount the app in kubernetes so I need to be able to externalize my configuration. Thanks in advance.

benjamin c :

Apparently it is due to invalid path declaration, to configure external properties/yml files you must use file: prefix for --spring.config.location.

So try this,

--spring.config.location="file:/path/to/myfile.yaml"

An alternative would be,

-Dspring.config.location="file:/path/to/myfile.yaml"

Make sure myfile.yaml is in the directory.


Official documentation: https://docs.spring.io/spring-boot/docs/2.1.9.RELEASE/reference/html/boot-features-external-config.html#boot-features-external-config-application-property-files

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to specify location of the YAML configuration file for Dask-YARN

Springboot external file db configuration

How to use SpringBoot PropertySource to read from an external configuration file

How to specify a GKE node pool configuration in a YAML file instead of using gcloud container node-pools create?

how to specify external software requirements with conda/meta.yaml in Python?

How to specify argparse options from an external file?

How to specify the redis configuration file in installation?

How to override SpringBoot config external file to classpath file?

How to specify external library file locations when installing CPAN modules

yaml file handlers configuration

How to use internal/external encoding when importing a YAML file?

How to add a external settings file in IIS configuration file

Springboot: how to set external location for profile file only?

How to specify order of spring handler interceptors in xml configuration file?

How can I specify the validity of a certificate in an OpenSSL configuration file?

How to specify Docker private registry credentials in Docker configuration File?

How do I specify an optional dependency in a CMake package configuration file?

How can I specify a configuration file in ArangoDB docker image?

How to specify configuration file for common_test running tests with rebar

How to validate values in a YAML configuration file while loading it?

Netplan: how do I apply specific configuration YAML file

How to check connection to database via YAML configuration file in Python?

External SpringBoot properties file on Docker

Specify jvm options in a configuration file

Docker pass configuration to yaml file

Read YAML configuration file in Python

How to load datasource configuration from external file in grails 3.1.8?

In Ratpack, how can I configure loading configuration from an external file?

Vue js with an external configuration file