Current location - Health Preservation Learning Network - Slimming men and women - After Springboot is typed into JAR package, the external configuration file is read.
After Springboot is typed into JAR package, the external configuration file is read.
The custom jar can only read application.properties and application.yml at present. You can use a simple method for listening injection, write an init method in the toolbox, and initialize it when springboot starts. For example, after springboot starts, read the configuration file and inject it into the toolkit.

When publishing a springboot project with a jar package, by default, application.properties in the same directory of the jar package will be used as the project configuration file first. However, if a configuration file is specified with-spring.config.location, the specified configuration file is read.

In this regard, we can "move" the configuration files of the springboot project outside the jar package, and then specify that it will use these external configuration files when starting the springboot project.

Here, we can use Java-jardemo-0.01-snapshot to run the project. Normal operation. When we input it into the jar package, application.properties will not be packaged into the jar package. It needs to be copied separately and put in jar package to run normally.

The profile SpringBoot uses the global profile application. Property application. YML。 The function of configuration file is to modify the default value of SpringBoot automatic configuration, which is automatically configured for us at the bottom.

Conventionally, in springboot, you only need to take the properties configured in appolo or nacos.