Spring Boot 02 EnvironmentPostProcessor接口
来源:互联网 发布:美化手机桌面主题软件 编辑:程序博客网 时间:2024/06/15 13:08
EnvironmentPostProcessor是Spring Boot的一个拓展接口,我们可以通过这个接口来添加配置文件。
可以通过http等方式构成一个Properties,实现统一的管理配置文件。
这里只是简单的实现在文件管理下的配置文件。
这是源码的解释,说明了该接口的实现类要在classpath:META-INT/spring.factories里面注册
Allows for customization of the application's {@link Environment} prior to theapplication 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;@Componentpublic class MyEnvironmentPostProcessor implements EnvironmentPostProcessor {@Overridepublic 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
阅读全文
0 0
- Spring Boot 02 EnvironmentPostProcessor接口
- Spring Boot # EnvironmentPostProcessor
- spring boot异步设计接口
- spring boot 文件上传接口设计
- spring-boot restful接口学习(1)
- spring-boot集成swagger(接口管理工具)
- spring boot(3)-Rest风格接口
- spring boot中用RabbitMQ调用接口
- Spring Boot 实例通过接口安全退出
- Spring Boot 实例通过接口安全退出
- Spring Boot -- Swagger之接口分组
- spring boot 调用接口超时解决 HystrixRuntime
- spring boot(3)-Rest风格接口
- spring-boot restful接口学习,postman工具
- Spring Boot集成JWT&Spring Security进行接口安全认证
- 【Spring Boot】Spring Boot
- Spring Boot系列八 spring boot集成jsp、restful接口、springmvc基本功能
- spring-boot集成springfox(Swagger) (ApiDoc接口文档)
- 关于pixhawk源码里面经常出现的结构体
- 关于ROS多机通信的总结 1.0
- [洛谷]最大流 模板
- android gradle 3.0.0 中依赖指令implementation、api 的区别
- 数据库事务的四大特性以及事务的隔离级别
- Spring Boot 02 EnvironmentPostProcessor接口
- maven整理
- Spring boot环境搭建
- maven JAR包冲突解决方案
- 利用mkfs.ubifs和ubinize两个工具制作UBI镜像
- HDU 1754
- 初探C++学习笔记
- 判断网络
- 数据结构——第三章算法设计题(2):判断是否为回文