Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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.