通过@Value + @PropertySource来给组件赋值
生活随笔
收集整理的這篇文章主要介紹了
通过@Value + @PropertySource来给组件赋值
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
public class Person {//通過普通的方式@Value("司馬")private String firstName;//spel方式來賦值@Value("#{28-8}")private Integer age;通過讀取外部配置文件的值@Value("${person.lastName}")private String lastName;}@Configuration
@PropertySource(value = {"classpath:person.properties"}) //指定外部文件的位置
public class MainConfig {@Beanpublic Person person() {return new Person();}}
?
總結
以上是生活随笔為你收集整理的通过@Value + @PropertySource来给组件赋值的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 通过Spring的BeanPostPro
- 下一篇: 自己写一个实现ApplicationLi