配置文件 src/main/resources 目录下: book.properties
yuyi.book.name=三国演义
yuyi.book.count=100
一、使用@Value 注解注入属性
package com.yuyi.bean.model;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
/**
* 使用 @Value 注解注入属性值
*/
@Component
public class BookValue {
@Value("${yuyi.book.name}")
private String name;
@Value("${yuyi.book.count}")
private Integer count;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getCount() {
return count;
}
public void setCount(Integer count) {
this.count = count;
}
}
二、使用 Environment 获取配置信息
package com.yuyi.bean.mo