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