@Component@PropertySource(value ={"classpath:demo.properties"})publicclassReadByPropertySourceAndValue{@Value("${demo.name}")privateString name;@Value("${demo.sex}")privateint sex;@Value("${demo.type}")privateString type;@OverridepublicStringtoString(){return"ReadByPropertySourceAndValue{"+"name='"+ name +'\''+", sex="+ sex +", type='"+ type +'\''+'}';}}
@PropertySource 和 @ConfigurationProperties
@Component@PropertySource(value ={"classpath:demo.properties"})@ConfigurationProperties(prefix ="demo")publicclassReadByPropertySourceAndConfProperties{privateString name;privateint sex;privateString type;publicvoidsetName(String name){this.name = name;}publicvoidsetSex(int sex){this.sex = sex;}publicvoidsetType(String type){this.type = type;}publicStringgetName(){return name;}publicintgetSex(){return sex;}publicStringgetType(){return type;}@OverridepublicStringtoString(){return"ReadByPropertySourceAndConfProperties{"+"name='"+ name +'\''+", sex="+ sex +", type='"+ type +'\''+'}';}}