java.lang.IllegalArgumentException: template not initialized; call afterPropertiesSet() before using


在使用spring-data-redis時使用junit測試報錯:
  java.lang.IllegalArgumentException: template not initialized; call afterPropertiesSet() before using

 

通過跟蹤代碼發現是這一句出了問題:

Assert.isTrue(this.initialized, "template not initialized; call afterPropertiesSet() before using it");

而initialized是在public void afterPropertiesSet() 中被賦值為true的。


解決方式:
不能直接在代碼中用new來直接實例化,必須得用SpingBean的實例化方式來!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM