SpringBoot在yml配置文件中配置druid的操作(2)

@Component @PropertySource("classpath:application-druid.yml") //指定yml文件位置 @ConfigurationProperties(prefix = "info") public class YmlConfig{ Map<String,String> user = new HashMap<>(); //user getter及setter方法 }

同样也能注入到user的Map对象。

指定任意层

如本文开始的那个yml配置文件的配置,如果,我想直接获取到所有的数据源的配置,那么就必须要指定一个对象能装下所有的这些配置,可以自定义对象,或者直接使用Map。如,我们定义如下的Map:

@Component @ConfigurationProperties(prefix = "spring.datasource") public class YmlConfig{ Map<String,Map<String,String>> druid = new HashMap<>(); //user getter及setter方法 }

Spring容器其中后,配置文件中spring.datasource.druid以下的配置属性同样能注入到druid对象中去。

同样指定其他层的配置,只要符合某个对象的数据结构,就能将配置的属性注入到该对象中去。

以上这篇SpringBoot在yml配置文件中配置druid的操作就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/809aed453a766243b27a2e10db97384e.html