I. Overview.
The previous blog describes the implementation of AOP using XML to implement AOP in the form of annotations, which now describes another AOP implementation.
Second, the code demonstration.
Preparation work Reference Previous blog "Rookie learning spring--60s using annotation to implement simple AOP"
Directory structure:
In fact, compared to the previous blog with annotation to implement the AOP approach we just have to change the Securityhandler.java and configuration file Applicationcontext.xml to the following content is possible. I'll write down the code for the two files below.
Securityhandler.java
Package Com.tgb.spring;public class securityhandler{private void CheckSecurity () {System.out.println ("checksecurity" );}}
Applicationcontext.xml
<?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:aop= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP" xmlns:tx= " Http://www.springframework.org/schema/tx "xsi:schemalocation=" Http://www.springframework.org/schema/beans http:/ /www.springframework.org/schema/beans/spring-beans-2.0.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP http://www. Springframework.org/schema/aop/spring-aop-2.0.xsd Http://www.springframework.org/schema/tx Http://www.springfram Ework.org/schema/tx/spring-tx-2.0.xsd "><bean id=" Usermanager "class=" Com.tgb.spring.UserManagerImpl "/> <bean id= "Securityhandler" class= "Com.tgb.spring.SecurityHandler"/><aop:config><aop:aspect id= " Securityaspect "ref=" Securityhandler "> <aop:pointcut id=" addaddmethod "expression=" Execution (* com.tgb.spring .*.*(..))" /><aop:before method= "CheckSecurity" pointcut-ref="Addaddmethod"/></aop:aspect></aop:config></beans>
:
Third, summary.
The XML implementation of AOP is not intrusive to the code and can be flexibly configured without recompiling. But one drawback is that too many configuration files are not good for management.
Rookie Learning spring--60s Configuration XML method for simple AOP