Spring简单的一个schema 介绍
2010-07-31 13:39
330 查看
文件结构:
配置文件
package com.macower.spring.aspectj; public class AdviceMethod { public void preExcute(){ System.out.println("------------preExcute------------"); } }
package com.macower.spring.aspectj; public class NiveWater { public void testAop(){ System.out.println("----------NiveWater.testAop()------"); } public void testOther(){ System.out.println("----------NiveWater.testOther()------"); } }
package com.macower.spring.aspectj; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import junit.framework.TestCase; public class TestAspectJ extends TestCase{ public void testBefore() throws Exception { ApplicationContext ctx = new ClassPathXmlApplicationContext("app*.xml"); NiveWater n = (NiveWater)ctx.getBean("niveWater");//测试没指定的类 //pointcut="target(com.macower.spring.aspectj.NiveWater) n.testAop();//测试<aop:aspect>中指定的方法 execution(* testAop(..) n.testOther();//测试<aop:aspect>中没有指定的方法 System.out.println("----------------------------------------"); TNiveWater tn = (TNiveWater)ctx.getBean("tniveWater");//测试没有指定的类 tn.testAop(); } }
package com.macower.spring.aspectj; public class TNiveWater { public void testAop(){ System.out.println("----------NiveWater.testAop()------"); } }
配置文件
<?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"> <aop:config proxy-target-class="true"> <aop:aspect ref="adviceMethod"><!-- 引用bean --> <!-- target在指定的类上面运用切点,and 表示与 execution 执行指定的表达式的方法,method表示需要在execution中切入的方法 --> <aop:before pointcut="target(com.macower.spring.aspectj.NiveWater) and execution(* testAop(..))" method="preExcute" /> </aop:aspect> </aop:config> <!-- 定义bean --> <bean id="adviceMethod" class="com.macower.spring.aspectj.AdviceMethod" /> <bean id="niveWater" class="com.macower.spring.aspectj.NiveWater" /> <bean id="tniveWater" class="com.macower.spring.aspectj.TNiveWater" /> </beans>
相关文章推荐
- 一个简单的schema介绍
- springboot - 一个最简单的Web应用
- Spring Data JPA 简单介绍
- SpringBoot | 第六章:常用注解介绍及简单使用
- 改变一个文件的拥有者,chown的简单介绍
- Spring 入门(一个简单的例子)
- Spring基于 Annotation 的简单介绍
- spring-context.xml 文件配置的简单介绍
- 综合应用WPF/WCF/WF/LINQ之三十八:实现一个简单的DataGrid之总体介绍
- 一个简单的Spring实现的例子
- 用tomcat+apacheServer+spring搭建一个集群,实现简单的负载均衡
- springmvc+mybaits的一个简单例子
- ActiveMQ简单使用介绍(一):未整合Spring情况下的介绍使用
- dubbo&hsf&spring-cloud简单介绍
- hibernate+spring的一个简单分页实现
- springmvc+hibernate的一个简单实例 推荐
- 介绍一个简单的 GPS 应用软件开发包
- 一个简单的Spring入门实例
- Spring3 -- IOC简单介绍 01
- 一个简单的SpringMVC需要哪些jar包[Spring4]