Springboot 中的注解 @EnableConfigurationProperties与@ConfigurationProperties
两种使用方式等价:
方式一: @Component 和 @ConfigurationProperties(prefix = "multi-tenant") 组合
package com.xx; import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; @Data @Component @ConfigurationProperties(prefix = "multi-tenant") public class MultiTenantProperties { private String ignoreTables; //逗号分割 private String tenantIdColumn; }
方式二: @ConfigurationProperties 和 @Configuration,@EnableConfigurationProperties组合
package com.xx; import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; @Data @ConfigurationProperties(prefix = "multi-tenant") public class MultiTenantProperties { private String ignoreTables; //逗号分割 private String tenantIdColumn; }
package com.xx; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Configuration; @Configuration @EnableConfigurationProperties(MultiTenantProperties.class) public class MultiTenantConfig { }
@ConfigurationProperties 注解,却又没有使用@Component等方式,导致无法被扫描为bean,那么就必须在@Coniguration对应配置类上使用@EnableConfigurationProperties注解去指定这个类,使得spring会扫描它,添加为bean,并识别@ConfigurationProperties注解,然后填充属性。
参考: https://www.cnblogs.com/sjkzy/p/14391304.html
分类:
boot
, spring boot
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
2019-03-11 设计风格Resultful
2019-03-11 swagger使用
2019-03-11 Spring boot中@RequestParam和@PathVariable区别