麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

Spring mvc 中有關 Shiro 1.2.3 配置問題

2019-11-14 21:15:32
字體:
來源:轉載
供稿:網友
SPRing mvc 中有關 Shiro 1.2.3 配置問題

Spring 版本:3.2.x, 4.0.x

【問題說明】

首先介紹下配置出錯情況:

(1)項目中,Spring3 and Spring4 的 applicationContext.xml aop 配置如下:

... ...   <aop:aspectj-autoproxy expose-proxy="true"/>       <tx:annotation-driven transaction-manager="transactionManager"/>   <tx:advice id="txAdvice" transaction-manager="transactionManager">        <tx:attributes>            <tx:method name="save*" propagation="REQUIRED" />            <tx:method name="add*" propagation="REQUIRED" />            <tx:method name="create*" propagation="REQUIRED" />            <tx:method name="insert*" propagation="REQUIRED" />            <tx:method name="update*" propagation="REQUIRED" />            <tx:method name="del*" propagation="REQUIRED" />            <tx:method name="get*" propagation="REQUIRED" read-only="true" />            <tx:method name="find*" propagation="REQUIRED" read-only="true" />            <tx:method name="query*" propagation="REQUIRED" read-only="true" />            <tx:method name="*"  read-only="true"/>        </tx:attributes>    </tx:advice>       <aop:config expose-proxy="true">        <!-- 只對業務邏輯層實施事務 -->        <aop:pointcut id="txPointcut" expression="execution(* com.app..service..*.*(..))" />        <aop:advisor advice-ref="txAdvice" pointcut-ref="txPointcut"/>    </aop:config>... ...

未加入 Shiro 之前,所有 applicationContext 的 getBean(...) 方法能正常獲取到相應對象實例。 調用getBeanDefinitionNames()輸出的 Beans 如下:

Bean NameBean Class
userDaoImplclass com.app.dao.impl.UserDaoImpl
resourceServiceImplclass com.app.service.impl.ResourceServiceImpl$$EnhancerBySpringCGLIB$$4ddf6901
roleServiceImplclass com.app.service.impl.RoleServiceImpl
userServiceImplclass com.app.service.impl.UserServiceImpl$$EnhancerBySpringCGLIB$$e7bcd944

以上 bean 都采用 @Repository 或@Service 的注解方式。

注意標紅Class名稱,這是因為被 CGLIB 動態代理。

(2)根據 Shiro 示例,新增配置文件 applicationContext-security.xml,然后配置Shiro 如下:

... ...    <bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">        <property name="realm" ref="myRealm"/>    </bean>    <bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor"/>    <bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator" depends-on="lifecycleBeanPostProcessor">    </bean>    <bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">        <property name="securityManager" ref="securityManager"/>    </bean>         <bean id="formAuthenticationFilter"  class="org.apache.shiro.web.filter.authc.FormAuthenticationFilter"/>... ...

加入 Shiro 之后,發現有些地方 getBean(...) 出錯,調用getBeanDefinitionNames()輸出的 Beans 如下:

Bean NameBean Class
userDaoImplclass com.app.dao.impl.UserDaoImpl
resourceServiceImplclass $Proxy38
roleServiceImplclass com.app.service.impl.RoleServiceImpl
userServiceImplclass $Proxy32

可以注意到標紅Class名稱,這是由于配置 DefaultAdvisorAutoProxyCreator,又被 JDK 動態二次代理。

【解決辦法】

兩次都以 CGLIB 動態代理。在 AOP 配置加上proxy-target-class 屬性,值為 true。具體如下:

(1)在 applicationContext.xml 中配置

... ...    <aop:config expose-proxy="true" proxy-target-class="true">        <!-- 只對業務邏輯層實施事務 -->        <aop:pointcut id="txPointcut" expression="execution(* com.app..service..*.*(..))" />        <aop:advisor advice-ref="txAdvice" pointcut-ref="txPointcut"/>    </aop:config>... ...

(2)在 applicationContext-security.xml 配置 Shiro

... ...    <bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator" depends-on="lifecycleBeanPostProcessor">        <property name="proxyTargetClass" value="true"/>      </bean>... ...

修改完成后,重新運行程序,getBean 恢復正常。

【參考資料】

spring的二次代理原因及如何排查 http://jinnianshilongnian.VEvb.com/blog/1894465


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 视频一区二区三区在线播放 | 色婷婷一区二区三区 | 久久精品国产清自在天天线 | 91久久国产露脸精品国产 | 成人短视频在线播放 | 羞羞的视频 | 精品成人av一区二区三区 | 久久国产一二三 | 免费观看黄色一级视频 | 巨乳毛片| 久久成人激情视频 | 欧美视频在线一区二区三区 | 久久精品久 | 国产无遮挡一区二区三区毛片日本 | 色网站综合 | 亚洲性生活免费视频 | 久久久久国产成人精品亚洲午夜 | 天堂成人国产精品一区 | 久久久久久久久久久久久九 | 欧美一级淫片免费视频1 | 国产国语毛片 | 精品免费在线视频 | 一区国产在线 | 欧美乱码精品一区 | 日韩精品一二三 | 亚洲网站一区 | 九九视屏 | 全黄裸片武则天艳史 | 国产69精品久久99不卡免费版 | 91小视频在线观看免费版高清 | 国产成人高清成人av片在线看 | 国产99视频精品免视看9 | 中国7777高潮网站 | 亚洲情视频 | 男人久久天堂 | 欧美国产精品一区二区 | 久久99久久99精品 | 欧美亚洲国产成人综合在线 | 亚洲欧美在线视频免费 | www.热 | 国产精品9191 |