前言:在后端开发当中我们可能会使用到工具类,而一般的工具类中的方法都是静态方法.而@Value注解只能给普通变量注入值,不能直接给静态变量赋值.

方案一:将Util类改写为Service类
利用Bean对象注入调用其中的方法,但这个方法不再是静态方法.
方案二:编写set()方法,并添加Component
注解

注意静态方法中传入的是静态变量

参考博客:
https://blog.csdn.net/mononoke111/article/details/81088472#commentBox
网友评论