天天看點

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;
    }
}