@NacosPropertySource
用来配置单个DataId
如:
@NacosPropertySource(dataId = "user.info", groupId = "springbootvue", autoRefreshed = true)
@NacosPropertySources
用来配置多个DataId
如:
@NacosPropertySources({
@NacosPropertySource(dataId = "user.info", groupId = "springbootvue", autoRefreshed = true),
@NacosPropertySource(dataId = "user.info.pre", groupId = "springbootvue", autoRefreshed = true),
@NacosPropertySource(dataId = "user.info.test", groupId = "springbootvue", autoRefreshed = true),
@NacosPropertySource(dataId = "user.info.test", groupId = "springbootvuetest", autoRefreshed = true)})
@NacosValue
用来获取Nacos中的值
但有个问题!
@NacosValue不能区分DataId。
也就是说,当用@NacosValue方式获取的key属性只能在所有接入的多DataId中是唯一的属性名,不然会造成取值错误。
所以Nacos提供了@NacosConfigurationProperties注解。
是不是很熟悉?对的,和@ConfigurationProperties是一样的道理。
定义并接收指定配置中的属性值
如:
@NacosConfigurationProperties(dataId = "user.info", groupId = "springbootvue", autoRefreshed = true)
然后在类中,定义和Nacos配置的key一样的属性名,就可以了!
这种方式支持String,Int等基本类型,像List,Map,Object等特殊类型,是不支持的!需要用string接收,然后在对应set方法中重新处理一下
@NacosPropertySource、@NacosPropertySources、@NacosValue、@NacosConfigurationProperties
于 2021-11-30 11:36:06 首次发布