@BindProps 用法说明
@BindProps 相当于 @Inject 的专业简化版本,且只关系属性的绑定。
| 注解 | 描述 | 可注解目标 | 区别 |
|---|---|---|---|
@Inject("${xxx}") | 注入配置 | 字段、参数、类 | 有 required 检测(没有配置时会异常提醒) |
@BindProps(prefix="xxx") | 绑定配置 | 类、方法 | 支持生成模块配置元信息 |
应用示例
示例1:
@BindProps(prefix="user.config") //或者用绑定属性注解。v3.0.7 后支持
@Configuration
public class UserProperties{
public String name;
public List<String> tags;
...
}
示例2:
@Configuration
public class DemoConfig {
@BindProps(prefix="user.config") //或者用绑定属性注解。v3.0.7 后支持
@Bean
public UserProperties userProperties(){
return new UserProperties();
}
}