第一種方式:
xx.properties 屬性名稱錯誤,未與@Value("${xxx}") 進行對應
第二種方式:
該類未注入到spring bean容器中
@Component
@Controller
@Service
# 上面未注入,使用 @Autowired 會報錯
@Autowired
第三種方式:
采用 new 等方式獲取該對象
@Component class TestValue{ @Value("${tag}") private String tagValue; } class Test{ ... TestValue testValue = new TestValue() } \
第四種方式
將該屬性 用 static final 等字眼進行 修飾
@Value("${value}")
private static String value; //錯誤
@Value("${value}")
private final String value; //錯誤
第五種方式
該屬性名 大寫
@Value("${value}") private static String VALUE; //錯誤
參考文檔:https://blog.csdn.net/zzmlake/article/details/54946346
第五種方式 是我真正遇到的,若還有其他方式會導致@Value("${xxx}") 為null ,
請在下方留言,