标签:范围 排除 tty prefix 注解 OLE 属性 实体类 AC
声明:
example.name=tom example.wife=jerry example.age=25 example.dream=top
@ConfigurationProperties(prefix = "example") @PropertySource(value = "classpath:config/config-test.properties") @Component public class ExampleConfig { private String name; private String wife; private String age; private String dream; get ... set }
// 自定义配置文件对应配置类 注入 @Autowired private ExampleConfig exampleConfig; @RequestMapping(value = "/hello",method = RequestMethod.GET) @ResponseBody public String sayHello(){ return exampleConfig.getName() + "的老婆是" + exampleConfig.getWife() + ", 年龄" + exampleConfig.getAge() + "岁,梦想是" + exampleConfig.getDream(); }
ConfigurationProperties源码:
@Target({ ElementType.TYPE, ElementType.METHOD }) @Retention(RetentionPolicy.RUNTIME) @Documented public @interface ConfigurationProperties { /** * The name prefix of the properties that are valid to bind to this object. Synonym * for {@link #prefix()}. * @return the name prefix of the properties to bind */ @AliasFor("prefix") String value() default ""; /** * The name prefix of the properties that are valid to bind to this object. Synonym * for {@link #value()}. * @return the name prefix of the properties to bind */ @AliasFor("value") String prefix() default ""; boolean ignoreInvalidFields() default false; boolean ignoreUnknownFields() default true; }
标签:范围 排除 tty prefix 注解 OLE 属性 实体类 AC
原文地址:https://www.cnblogs.com/nyatom/p/9072902.html