1、自定义监听器实现接口
public class Study implements EnvironmentPostProcessor {
@Override
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
System.out.println("-------开始加载自定义配置-------");
Properties properties = new Properties();
properties.setProperty("wxwxwx","hfhfhfhfh");
PropertySource<?> propertySource = new PropertiesPropertySource("wxwxwx1", properties);
environment.getPropertySources().addLast(propertySource);
System.out.println("-------结束加载自定义配置-------");
}
}
2、创建META-INF文件夹,创建spring.factories文件;添加自定义监听器
org.springframework.boot.env.EnvironmentPostProcessor=\
com.iss.ioc.vehicle.vehicle.service.Study