SpringBoot 疑難雜癥匯總

未添加模板引擎@RequestMapping無(wú)法顯示Html頁(yè)面(404錯(cuò)誤)

新建的Springboot項(xiàng)目pom.xml

<!---至少要添加一個(gè)模板引擎,要不然@RequestMapping無(wú)法顯示Html頁(yè)面(404錯(cuò)誤)->
<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-web</artifactId>
</dependency>

Springboot整合Shiro安全驗(yàn)證框架導(dǎo)致@Service 注入失敗

public class ShiroRealmWrapper extends AuthorizingRealm {

    @Autowired
    public UserInfoService userInfoService;// null
    ....
}

折騰了半宿,看到有網(wǎng)友已經(jīng)提前采坑:Shiro解決無(wú)法注入Service問(wèn)題

按照這個(gè)網(wǎng)友的說(shuō)法
對(duì)于SpringMVC框架:ShiroRelam屬于filter即過(guò)濾器,它在Spring未完成注入bean之前就已經(jīng)攔截了,因此無(wú)法注入。
對(duì)于SpringBoot,沒有將ShiroRealm注入Bean。
ShiroConfig在注入SecurityManager時(shí)setRealm()的參數(shù)ShiroRealm不能自己new出來(lái),而要先將其注入Bean

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容