Rookie Learning spring--60s Configuration XML method for simple AOP

Source: Internet
Author: User

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

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.