注入属性文件的值
按照以往的方式,我们总是直接把具体的字面量值填入代码进行字面量值的注入。如下所示:
1 @Component 2 public class Music { 3 private String musicName = null; 4 private Date publishTime = null; 5 6 @Value("Dream") 7 public void setMusicName(String musicName) { 8 this.musicName = musicName; 9 } 10 11 @Value("2022/12/22") 12 public void setPublishTime(Date publishTime) { 13 this.publishTime = publishTime; 14 } 15 16 // 省略getter方法 17 }