一般情況的下的@Value是用在非靜態方法上的,如下:
import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @Component public class WebServiceConstants { @Value("${ws_charging_url}") public String feeUrl; }
但是對於靜態變量,我們需要采取不同的方式:
一、xml通過bean注入:沒有嘗試,理論上可行
二、給參數注入,執行set方法
三、通過中間變量賦值