属性赋值-@PropertySource加载外部配置文件
配置类上添加注解@PropertySource加载外部配置文件
@Configuration @PropertySource("classpath:/person.properties") @ComponentScan(value = "com.yyc", includeFilters ={@ComponentScan.Filter(type= FilterType.CUSTOM, classes={MyTypeFilter.class})}, useDefaultFilters = false) public class MainConfig { // 可以自定义一个bean的id,否则方法名即为beanId @Bean("person") public Person person() { return new Person(); } }
@Value("13") private int age; @Value("${name}") private String name;
Person{age=13, name='zhangsan'}
posted on 2019-05-25 15:24 星辰钟塔的玛利亚女士 阅读(287) 评论(0) 编辑 收藏 举报