static变量使用@Value注入小纪

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u012760435/article/details/82683797

Spring 不允许(or 不支持?)把值注入到静态变量中,需要通过setter方法进行注入,如下

private static String MESSAGEURL;

@Value("${verification.message}")
public void setMESSAGEURL(String messageUrl) {
    VerificationCode.MESSAGEURL = messageUrl;
}

注意setter方法不可以为static!
除此之外需要在类名上添加@Component注解

猜你喜欢

转载自blog.csdn.net/u012760435/article/details/82683797