How springboot project jar package introduces external configuration file

      

 springboot project labeled jar package, the default configuration file is read in the classpath, the config.properties custom profile.

 

If the bag should config.properties arranged on the outside of the jar, to facilitate configuration changes,

 

 1. added to the starting class or classes disposed @PropertySource annotation, value parameters scan path may be multiple, when ignoreResourceNotFound true, the start of the project, starting with the first to find a path to the configuration file, if not find to, look for the second path, and so on ...

@Data
@Component
@ConfigurationProperties
@PropertySource(value = {"classpath:config.properties","file:${spring.profiles.path}/config.properties"},ignoreResourceNotFound = true)
public class ConfigBean {
 
 
 
}

spring.profiles.path: Road config.properties file is located, can be configured in application.yml,

For convenience, however, spring.profiles.path usually when incoming jar package starts:

java -jar xxx.jar --spring.profiles.path=xxx

In this way, jar start time to read custom configuration file according to the parameters passed

 

Article reprint to: https://blog.csdn.net/wsgsm/article/details/83274362

 

Guess you like

Origin www.cnblogs.com/nhdlb/p/11718607.html