SpringBoot項目無法將配置文件中的值注入到靜態變量中解決方案

SpringBoot項目無法將配置文件中的值注入到靜態變量中解決方案

package club.yueshe.pangu.config;

import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

/**
 * @Author Theodore
 * @Date 2019/10/23 16:14
 */
@Data
@Configuration
public class FastDFSConfig {

    public static String fastDFSIpAndPort;

    /**
     * 必須使用 @Autowired ,否則無法注入數據
     * @param ipAndPort
     */
    @Autowired
    public void setFastDFSIpAndPort(@Value("${fastdfs.ipAndPort}") String ipAndPort) {
        fastDFSIpAndPort = ipAndPort;
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章