- 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.MyEnvironmentPostProcessor
Now, file(s) will be loaded if exists.
classpath:my-project.conf
classpath:my-project.toml
classpath:my-project.yml
classpath:my-project.yaml
classpath:my-project.properties
classpath:my-project.xml
(also properties)
Also, file(s) will be loaded if exists and myprofile
profile is active.
classpath:my-project-myprofile.conf
classpath:my-project-myprofile.toml
classpath:my-project-myprofile.yml
classpath:my-project-myprofile.yaml
classpath:my-project-myprofile.properties
classpath: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