- Java 8+
- SpringBoot 2.2.0+
- maven / gradle is highly recommended.
<dependency>
<groupId>com.github.yingzhuo</groupId>
<artifactId>spring-boot-stater-env</artifactId>
<version>2.0.3</version>
</dependency>@Configuration
@PropertySource(value = "classpath:/config.toml", factory = TomlPropertySourceFactory.class)
public class ApplicationConfig {
// ...
}@Configuration
@PropertySource(value = "classpath:/config.yaml", factory = YamlPropertySourceFactory.class)
public class ApplicationConfig {
// ...
}@Configuration
@PropertySource(value = "classpath:/config.conf", factory = HoconPropertySourceFactory.class)
public class ApplicationConfig {
// ...
}package my.project;
public class MyEnvironmentPostProcessor extends AbstractConventionEnvironmentPostProcessor {
@Override
protected String getName(ConfigurableEnvironment environment, SpringApplication application) {
return "property-source";
}
@Override
protected String[] getLocationsPrefix(ConfigurableEnvironment environment, SpringApplication application) {
return new String[]{
"classpath:my-project"
};
}
}DO NOT forget to register it. In your classpath:/META-INF/spring.factories:
org.springframework.boot.env.EnvironmentPostProcessor=my.project.MyEnvironmentPostProcessorNow, file(s) will be loaded if exists.
classpath:my-project.confclasspath:my-project.tomlclasspath:my-project.ymlclasspath:my-project.yamlclasspath:my-project.propertiesclasspath:my-project.xml(also properties)
Also, file(s) will be loaded if exists and myprofile profile is active.
classpath:my-project-myprofile.confclasspath:my-project-myprofile.tomlclasspath:my-project-myprofile.ymlclasspath:my-project-myprofile.yamlclasspath:my-project-myprofile.propertiesclasspath:my-project-myprofile.xml(also properties)
- Fork it
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'add some feature')
- Push to the branch (git push origin my-new-feature)
- Create new Pull Request
- 应卓 - github
Apache 2.0 license. See LICENSE