<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
<property name="cacheManager" ref="shiroCacheManager" />
<property name="authenticator" ref="authenticator"></property>
</bean>
<bean id="authenticator" class="org.apache.shiro.authc.pam.ModularRealmAuthenticator">
<property name="realms">
<list>
<ref bean="authenticationRealm"/>
<ref bean="secondRealm"/>
</list>
</property>
<bean class="org.apache.shiro.authc.pam.FirstSuccessfulStrategy"></bean>
</property>
</bean>
以上配置会出现Configuration error: No realms have been configured! One or more realms must be present to execute an authorization operation.
改成以下配置就可以了,authenticator和realms的先后顺序导致的问题
<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
<property name="cacheManager" ref="shiroCacheManager" />
<property name="authenticator" ref="authenticator"></property>
<property name="realms">
<list>
<ref bean="authenticationRealm"/>
<ref bean="secondRealm"/>
</list>
</property>
</bean>
<bean id="authenticator" class="org.apache.shiro.authc.pam.ModularRealmAuthenticator">
<property name="authenticationStrategy">
<bean class="org.apache.shiro.authc.pam.FirstSuccessfulStrategy"></bean>
</property>
</bean>