Ask Your Question
0

What can be done to stop spring-boot from attempting to load application.properties and use properties that we have defined?

asked 2022-12-11 11:00:00 +0000

lakamha gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-06-28 00:00:00 +0000

qstack gravatar image

There are a few ways to prevent Spring Boot from loading the default application.properties file or other configuration files. Here are some options:

  1. Specify a different configuration file location: You can tell Spring Boot to look for your configuration file in a specific location using the spring.config.name and spring.config.location properties. For example, you can run your application with the following command line options to specify a different configuration file:

java -jar myapp.jar --spring.config.name=myapp --spring.config.location=/path/to/config/

This tells Spring Boot to look for a file called myapp.properties or myapp.yml in the /path/to/config/ directory.

  1. Disable auto-configuration: If you don't want Spring Boot to auto-configure your application, you can set the spring.autoconfigure.exclude property to a comma-separated list of auto-configuration classes to exclude. For example, to disable all auto-configuration, you can add the following to your application.properties file:

spring.autoconfigure.exclude=*

  1. Use environment variables: You can also use environment variables to configure your application instead of application.properties. Spring Boot automatically maps system properties and environment variables to properties in your application. For example, you can set the server.port property using an environment variable called SERVER_PORT:

export SERVER_PORT=8080

  1. Use profiles: Spring Boot supports the concept of profiles, which allow you to define different sets of properties for different environments (e.g., development, production, etc.). You can activate a profile using the spring.profiles.active property. For example, you can define a development profile in a file called application-development.properties and activate it using the following command line option:

java -jar myapp.jar --spring.profiles.active=development

This tells Spring Boot to load properties from the application-development.properties file instead of the default application.properties.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-12-11 11:00:00 +0000

Seen: 8 times

Last updated: Jun 28 '21