public class MyPropertySource extends EnumerablePropertySource<Map<String,String>> {
public MyPropertySource(String name, Map source) {
super(name, source);
}
//获取所有的配置名字
@Override
public String[] getPropertyNames() {
return source.keySet().toArray(new String[source.size()]);
}
//根据配置返回对应的属性
@Override
public Object getProperty(String name) {
return source.get(name);
}
}
public class MyPropertySourceLocator implements PropertySourceLocator {
@Override
public PropertySource<?> locate(Environment environment) {
//简单起见,这里直接创建一个map,你可以在这里写从哪里获取配置信息。
Map<String,String> properties = new HashMap<>();
properties.put("myName","lizo");
MyPropertySource myPropertySource = new MyPropertySource("myPropertySource",properties);
return myPropertySource;
}
}
@Configuration
public class MyConfigBootstrapConfiguration {
@Bean
public MyPropertySourceLocator myPropertySourceLocator(){
return new MyPropertySourceLocator();
}
}
org.springframework.cloud.bootstrap.BootstrapConfiguration=\ com.lizo.MyConfigBootstrapConfiguration
@SpringBootApplication
public class Test2 {
public static void main(String[] args) throws SQLException {
ConfigurableApplicationContext run = SpringApplication.run(Test2.class, args);
Ser bean = run.getBean(Ser.class);
System.out.println(bean.getMyName());
}
@Component
public static class Ser{
@Value("${myName}")
private String myName;
public String getMyName() {
return myName;
}
public void setMyName(String myName) {
this.myName = myName;
}
}
}
my.name=${myName}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有