Spring Boot 02 EnvironmentPostProcessor接口
2017-11-02 18:47
162 查看
EnvironmentPostProcessor是Spring Boot的一个拓展接口,我们可以通过这个接口来添加配置文件。
可以通过http等方式构成一个Properties,实现统一的管理配置文件。
这里只是简单的实现在文件管理下的配置文件。
这是源码的解释,说明了该接口的实现类要在classpath:META-INT/spring.factories里面注册
实现类MyEnvironmentPostProcessor
spring.factories
可以通过http等方式构成一个Properties,实现统一的管理配置文件。
这里只是简单的实现在文件管理下的配置文件。
这是源码的解释,说明了该接口的实现类要在classpath:META-INT/spring.factories里面注册
Allows for customization of the application's {@link Environment} prior to the application context being refreshed. <p> EnvironmentPostProcessor implementations have to be registered in {@code META-INF/spring.factories}, using the fully qualified name of this class as the key. <p> {@code EnvironmentPostProcessor} processors are encouraged to detect whether Spring's {@link org.springframework.core.Ordered Ordered} interface has been implemented or if the @{@link org.springframework.core.annotation.Order Order} annotation is present and to sort instances accordingly if so prior to invocation.
实现类MyEnvironmentPostProcessor
import org.springframework.boot.SpringApplication; import org.springframework.boot.env.EnvironmentPostProcessor; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.PropertiesPropertySource; import org.springframework.stereotype.Component; @Component public class MyEnvironmentPostProcessor implements EnvironmentPostProcessor { @Override public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) { System.out.println("1"); Properties properties=null; try{ properties =new Properties(); properties.load(new FileInputStream("E:/SpringBoot/application1.properties")); PropertiesPropertySource propertySource =new PropertiesPropertySource("ds", properties); environment.getPropertySources().addLast(propertySource); } catch(Exception e){ e.printStackTrace(); } } }
spring.factories
org.springframework.boot.env.EnvironmentPostProcessor=com.springboot.www.config.MyEnvironmentPostProcessor
相关文章推荐
- springboot vue 登陆发送请求(跨域问题)02
- Spring Boot基础 - Web应用 - 02
- 在IDEA中导入Gradle构建的SpringBoot Web项目(SpringBoot-02)
- 02-SpringBoot——Spring基础-Java配置
- Scala开发者的Spring-Boot快速上手指南 02:Scala惯用法
- SpringBoot详细研究-02数据访问
- spring boot 学习--08---搭建ssmm-02
- 【Spring Boot】02 - 用Spring Boot创建Java应用
- springboot-02thymeleaf注意
- 玩转SpringBoot - 02 自定义配置文件
- (02) SpringBoot 配置文件使用
- Spring Boot 1.4.0 Release Notes 更新日志-02
- SpringBoot_Exception_02_Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.5.6.RELEASE:run
- SpringBoot-02热部署
- 一起学JAVA之《spring boot》02-开发您的第一个Spring Boot应用程序
- 【SpringBoot学习笔记】SpringBoot_02_vue和SpringBoot的跨域请求
- SpringBoot Beans管理和自动配置 火推 02
- Spring Boot系列02-Spring Boot + JSP 整合进行网页开发
- Spring Boot-Spring Tool Suit + Gradle 构建第一个Spring Boot 项目02
- SpringBoot学习教程 - 02 - 配置DevTools,实现热部署