Shiro集成Spring框架并且多Realms报错No realms have been configured! One or more realms must be ……解决办法

   博主今天在做Shiro集成SpringMVC实现多Reamls的时候,报了No realms have been configured! One or more realms must be ……的错误,百度了很久,解决了这个bug,现在分享给大家:

   在Spring的配置文件中:

  如:

  <bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
        <property name="cacheManager" ref="cacheManager"/>

         <!--把authenticator配置成securityManager的一个属性-->
         <property name="authenticator" ref="authenticator"></property>
            <!--配置的realms属性是一个集合 ,ref执行每个集合-->
         <property name="realms">
               <list>
                 <ref bean="jdbcRealm"></ref>
                 <ref bean="SecondRealm"></ref>
               </list> 
         </property>
    </bean>
    <!--配置多个Realm 需要配置ModularRealmAuthenticator -->
    <bean id="authenticator" class="org.apache.shiro.authc.pam.ModularRealmAuthenticator">
      
         <!--在 ModularRealmAuthenticator下面配置Shiro认证策略-->
        <property name="authenticationStrategy">
              <bean class="org.apache.shiro.authc.pam.AllSuccessfulStrategy"></bean>
        </property>
    
    </bean>


解决办法就是:

     <property name="authenticator" ref="authenticator"></property>

一定要在:

 <property name="realms">
               <list>
                 <ref bean="jdbcRealm"></ref>
                 <ref bean="SecondRealm"></ref>
               </list> 
         </property>

前面,不然会报错,楼主之前就是没有注意这点犯的错误!希望对大家有帮助!

猜你喜欢

转载自blog.csdn.net/qq_32575047/article/details/80684140