日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學(xué)無先后,達者為師

網(wǎng)站首頁 編程語言 正文

springboot下Static變量通過@Value和set方法注入失敗的問題和解決辦法

作者:請你保持微笑 更新時間: 2022-03-14 編程語言

首先static變量是不能直接使用@value進行注入。
但是也不是沒有辦法。操作如下:
1.在這個變量的類上標(biāo)上注解@Component
在這里插入圖片描述

2.通過set方法就可以,給在set方法上使用@Value注入。前提是set方法也不能是static類型的。如下:
public static int dataFrameLength;

public  int getDataFrameLength() {
    return dataFrameLength;
}

@Value("${dataFrameLength}")
public  void setDataFrameLength(int dataFrameLength) {
    Init.dataFrameLength = dataFrameLength;
}

但是我不知道什么原因即使我這樣做了也會注入失敗。

我的解決辦法,在另一個類Init中進行注入,然后從Init中拿過來。
在這里插入圖片描述

原文鏈接:https://blog.csdn.net/qq_39286701/article/details/121678481

欄目分類
最近更新