对于用static修饰的静态字段,直接用@Value("${xxx}")
无法注入,需要以下几步:
1.在类上添加@Component
注解
2.字段需要有set
方法
3.在set方法上使用@Value("${xxx}")
例子:
@Component
public class Sender {
public static String filePath;
@Value("${filePath}")
public void setFilePath(String file_path) {
filePath = file_path;
}
}