语法
@value(" ${"key"} ")
@value(" ${"key:defualtValue"} ")
- applicationContext.xml
<!-- 导入属性文件 -->
<context:property-placeholder location="classpath:config.properties"/>
- config.properties
name=张三
age=25
示例
public class User {
@Value("${"name"}") private String name; private int age;
public void setName(String name) { this.name = name; } @Value("${"age"}") public void setAge(int age) { this.age = age; }
|