1. 不能直接给静态属性注入值
如果必须是静态属性注入 可以使用set方法来注入值
@Component
public class Test{
public static String VALUE;
@Value("${propeties.string}")
public void setVALUE(String s) {
VALUE = s;
}
2。被注入的属性必须是spring的托管类
3.配置文件问题 springMvc 和 spring 是两个容器
如果加载配置文件在spring容器中 springMvc注入属性 会找不到配置文件
不使用spring 也可使用如下方法注入 属性
private static Properties props;
public static final String channelUser ;
static{
props = PropertyUtil.getInstance().createProperties("/function.properties");
channelUser = props.getProperty("function.channelUser").trim();
}