菜鸟学习Spring——60s配置XML方法实现简单AOP
2014-10-27 14:31
399 查看
一、概述。
上一篇博客讲述了用注解的形式实现AOP现在讲述另外一种AOP实现的方式利用XML来实现AOP。
二、代码演示。
准备工作参照上一篇博客《菜鸟学习Spring——60s使用annotation实现简单AOP》
目录结构:
其实比起上一篇博客中用annotation来实现AOP的方式我们只要把SecurityHandler.java和配置文件applicationContext.xml更改为下面内容就可以了。下面我把这两个文件的代码写下来。
SecurityHandler.java
applicationContext.xml
效果图:
三、总结。
XML实现的AOP对代码没有了侵入性并且能够灵活的配置不用重新编译。但是有个缺点就是配置文件太多了不好管理。
上一篇博客讲述了用注解的形式实现AOP现在讲述另外一种AOP实现的方式利用XML来实现AOP。
二、代码演示。
准备工作参照上一篇博客《菜鸟学习Spring——60s使用annotation实现简单AOP》
目录结构:
其实比起上一篇博客中用annotation来实现AOP的方式我们只要把SecurityHandler.java和配置文件applicationContext.xml更改为下面内容就可以了。下面我把这两个文件的代码写下来。
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.springframework.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>
效果图:
三、总结。
XML实现的AOP对代码没有了侵入性并且能够灵活的配置不用重新编译。但是有个缺点就是配置文件太多了不好管理。
相关文章推荐
- 菜鸟学习Spring——60s配置XML方法实现简单AOP
- 菜鸟学习Spring——60s配置XML方法实现简单AOP
- Spring AOP详解及通过XML配置实现的实现方法
- 菜鸟学习Spring——60s使用annotation实现简单AOP
- 在MyEclipse中,学习xml,配置aop的方法:如下:
- 菜鸟学习Spring——60s使用annotation实现简单AOP
- Spring 4.0 学习日记(9) ---XML配置实现AOP切面
- Struts2基于XML配置方式实现对action的所有方法进行输入校验
- 关于简单SSH框架中的web.xml的那些配置要点---->菜鸟一定要看哦
- 复习struts2之基于XML配置方式实现对action的所有方法进行校验
- Log4j简单实用例子 Log4j xml配置方法
- Emit学习-实战篇-实现一个简单的AOP框架(一)
- 第二十二章 基于XML配置方式实现对action的所有方法进行校验
- web项目取得spring配置的数据源的简单实现方法
- 简单实现MySQL服务器的优化配置方法
- 微软企业库5.0 学习之路——UnityPIAB 通过配置实现AOP
- C#操作xml配置文件最简单方法
- Spring Aop实现——Annotation方式(注解式)and Schema-based式(xml配置)
- Struts2学习笔记(十四):基于XML配置方式实现对action的所有方法进行校验
- AOP学习-基于Emit和Attribute的简单AOP实现