语法
@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; }
|
@value使用外部属性配置文件
https://notebook.itea.dev/2022/11/28/Spring/DI 使用注解/属性注入(@Value)/@value使用外部属性配置文件/index.html