Shiro 1.2.3 configuration problems in Spring mvc

Source: Internet
Author: User

Shiro 1.2.3 configuration problems in Spring mvc
Spring version: 3.2.x, 4.0.x [Problem description] first introduces the configuration error: (1) applicationContext of Spring3 and Spring4 in the project. the xml aop configuration is as follows: copy the code ...... <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 = "REQUI RED "/> <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-o Nly = "true"/> <tx: method name = "*" read-only = "true"/> </tx: attributes> </tx: advice> <aop: config expose-proxy = "true"> <! -- Only implement transactions on the business logic layer --> <aop: pointcut id = "txPointcut" expression = "execution (* com. app .. service .. *. *(..)) "/> <aop: advisor advice-ref =" txAdvice "pointcut-ref =" txPointcut "/> </aop: config> ...... before the replication code is added to Shiro, all getbeans (...) of applicationContext (...) method to obtain the corresponding object instance. The Beans output by calling getBeanDefinitionNames () are as follows: Bean Name Bean ClassuserDaoImpl class com. app. dao. impl. userDaoImplresourceServiceImpl class com. app. service. impl. resourceServiceImpl $ EnhancerBySpringCGLIB $ 4ddf6901roleServiceImpl class com. app. service. impl. roleServiceImpluserServiceImpl class com. app. service. impl. userServiceImpl $ EnhancerBySpringCGLIB $ e7bcd944 and above beans all use the @ Repository or @ Service annotation method. Note that the Class name is highlighted in red because it is dynamically represented by CGLIB. (2) According to the Shiro example, add the configuration file applicationContext-security.xml and configure Shiro as follows: copy the code ...... <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. defaultAdvisorAutoProxyCreato R "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 "/> ...... after the code is added to Shiro, getBean (...) is found in some places (...) an error occurred while calling the Bea output by getBeanDefinitionNames (). Ns: Bean Name Bean ClassuserDaoImpl class com. app. dao. impl. userDaoImplresourceServiceImpl class $ Proxy38roleServiceImpl class com. app. service. impl. roleServiceImpluserServiceImpl class $ Proxy32 you can note the red Class name, because the DefaultAdvisorAutoProxyCreator is configured and is also used by the JDK Dynamic secondary proxy. [Solution] both use CGLIB dynamic proxy. Add the proxy-target-class attribute to the AOP configuration. The value is true. The details are as follows: (1) In applicationContext. configure the copy code in xml ...... <aop: config expose-proxy = "true" proxy-target-class = "true"> <! -- Only implement transactions on the business logic layer --> <aop: pointcut id = "txPointcut" expression = "execution (* com. app .. service .. *. *(..)) "/> <aop: advisor advice-ref =" txAdvice "pointcut-ref =" txPointcut "/> </aop: config> ...... copy code (2) Configure Shiro in applicationContext-security.xml ...... <bean class = "org. springframework. aop. framework. autoproxy. defaultAdvisorAutoProxyCreator "depends-on =" lifecycleBeanPostProcessor "> <property name =" proxyTarge TClass "value =" true "/> </bean>... after the modification is complete, run the program again and getBean returns to normal.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.