shiro的配置文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"
default-lazy-init="false">
<!-- 項目自定义的Realm -->
<bean id="shiroDbRealm" class="com.szm.core.dao.realm.ShiroDbRealm"></bean>
<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
<property name="realm" ref="shiroDbRealm" />
<property name="sessionManager" ref="sessionManager" />
<property name="sessionMode" value="http"></property>
</bean>
<!-- Shiro Filter -->
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
<property name="securityManager" ref="securityManager" />
<property name="loginUrl" value="/login.jsp" />
<property name="successUrl" value="/homepage.jsp" />
<property name="unauthorizedUrl" value="/WEB-INF/jsp/errorPage/unauthorized.jsp" />
<property name="filterChainDefinitions">
<value>
/login.jsp* = anon
/test/login.action* = anon
/index.jsp*= anon
/error.jsp*= anon
/*.jsp* = authc
/*.action* = authc
</value>
</property>
</bean>
<bean id="sessionDAO"
class="org.apache.shiro.session.mgt.eis.EnterpriseCacheSessionDAO" />
<bean id="sessionManager"
class="org.apache.shiro.web.session.mgt.DefaultWebSessionManager">
<property name="sessionDAO" ref="sessionDAO" />
</bean>
<bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor" />
<bean
class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"
depends-on="lifecycleBeanPostProcessor" >
<property name="proxyTargetClass" value="true"></property>
</bean>
<bean
class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">
<property name="securityManager" ref="securityManager" />
</bean>
</beans>
如果出现代理异常:问题肯定在:spring配置文件默认的jdk动态代理,而cglib目标对象动态代理则必须配置 <property name="proxyTargetClass" value="true"></property>。代理冲突,则都改为cglib代理
如果是注解报异常:在action中的service实体类用spring注解@Autowired,而且要放在它的set方法上面。切记,创建的service实体类的名称一定要和service的接口实现类名一样。