网上的所有解决方法都看了个遍,还是没有解决这个bug.这是在使用spring集成shiro时报的错误。
错误如下:
web.xml中配置如下:


spring-shiro.xml如下:
<!--1.配置SecurityManager-->
<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
<property name="cacheManager" ref="cacheManager" />
<property name="realm" ref="shiroRealm" />
<!--<property name="realms">
<list>
<ref bean="shiroRealm"/>
</list>
</property>-->
</bean>
<!-- 2. 配置缓存管理器 cacheManager -->
<bean id="cacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager">
<!--<property name="cacheManager" ref="ehCacheManager"/>-->
<property name="cacheManagerConfigFile" value="classpath:ehcache.xml" />
</bean>
<!-- 3. 项目自定义的Realm -->
<bean id="shiroRealm" class="com.interceptor.ShiroRealm" />
<!-- 4. Shiro生命周期处理器,可以自动的来调用配置在spring IOC 容器中shiro bean的生命周期方法-->
<bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor" />
<!--5. 启用 IOC 容器中使用 shiro 的注解. 但必须在配置了 LifecycleBeanPostProcessor 之后才可以使用.-->
<bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator" depends-on="lifecycleBeanPostProcessor"/>
<!--6. 配置 ShiroFilter.
6.1 id 必须和 web.xml 文件中配置的 DelegatingFilterProxy 的 <filter-name> 一致.
若不一致, 则会抛出: NoSuchBeanDefinitionException. 因为 Shiro 会来 IOC 容器中查找和 <filter-name> 名字对应的 filter bean.
-->
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
<property name="securityManager" ref="securityManager"/> <!--安全管理-->
<property name="loginUrl" value="/"/> <!--登录页面-->
<property name="successUrl" value="/index.jsp"/> <!--登录成功后页面-->
<property name="unauthorizedUrl" value="/login/login"/>
<!--
配置哪些页面需要受保护.以及访问这些页面需要的权限.
1). anon 可以被匿名访问
2). authc 必须认证(即登录)后才可能访问的页面.
3). logout 登出.
4). roles 角色过滤器
-->
<property name="filterChainDefinitions">
<value>
<!--请求登录-->
/admin/login = anon
<!-- /login.jsp = anon
/shiro/login = anon
/shiro/logout = logout
/user.jsp = roles[user]
/admin.jsp = roles[admin]-->
<!--静态资料-->
/static/login/**
/static/js/**
# everything else requires authentication:
/** = authc
</value>
</property>
</bean>
错误如下:

web.xml中配置如下:


spring-shiro.xml如下:
<!--1.配置SecurityManager-->
<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
<property name="cacheManager" ref="cacheManager" />
<property name="realm" ref="shiroRealm" />
<!--<property name="realms">
<list>
<ref bean="shiroRealm"/>
</list>
</property>-->
</bean>
<!-- 2. 配置缓存管理器 cacheManager -->
<bean id="cacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager">
<!--<property name="cacheManager" ref="ehCacheManager"/>-->
<property name="cacheManagerConfigFile" value="classpath:ehcache.xml" />
</bean>
<!-- 3. 项目自定义的Realm -->
<bean id="shiroRealm" class="com.interceptor.ShiroRealm" />
<!-- 4. Shiro生命周期处理器,可以自动的来调用配置在spring IOC 容器中shiro bean的生命周期方法-->
<bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor" />
<!--5. 启用 IOC 容器中使用 shiro 的注解. 但必须在配置了 LifecycleBeanPostProcessor 之后才可以使用.-->
<bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator" depends-on="lifecycleBeanPostProcessor"/>
<!--6. 配置 ShiroFilter.
6.1 id 必须和 web.xml 文件中配置的 DelegatingFilterProxy 的 <filter-name> 一致.
若不一致, 则会抛出: NoSuchBeanDefinitionException. 因为 Shiro 会来 IOC 容器中查找和 <filter-name> 名字对应的 filter bean.
-->
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
<property name="securityManager" ref="securityManager"/> <!--安全管理-->
<property name="loginUrl" value="/"/> <!--登录页面-->
<property name="successUrl" value="/index.jsp"/> <!--登录成功后页面-->
<property name="unauthorizedUrl" value="/login/login"/>
<!--
配置哪些页面需要受保护.以及访问这些页面需要的权限.
1). anon 可以被匿名访问
2). authc 必须认证(即登录)后才可能访问的页面.
3). logout 登出.
4). roles 角色过滤器
-->
<property name="filterChainDefinitions">
<value>
<!--请求登录-->
/admin/login = anon
<!-- /login.jsp = anon
/shiro/login = anon
/shiro/logout = logout
/user.jsp = roles[user]
/admin.jsp = roles[admin]-->
<!--静态资料-->
/static/login/**
/static/js/**
# everything else requires authentication:
/** = authc
</value>
</property>
</bean>