public class People {
public void eat() {
System.out.println(“happyheng开始吃饭啦");
}
public void play(){
}
}
@Aspect
public class Servant {
/**
* 在吃饭之前
*/
@Before("execution(** com.happyheng.entity.People.eat(..))")
public void prepareFood(){
System.out.println("准备食物");
}
/**
* 在吃饭之后
*/
@After("execution(** com.happyheng.entity.People.eat(..))")
public void clean(){
System.out.println("打扫");
}
}
<?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" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd" xmlns:context="http://www.springframework.org/schema/context"> <context:component-scan base-package="com.happyheng" /> <aop:aspectj-autoproxy /> <!--注意Aspect的bean必须在Spring中注册,否则不会生效,Spring会用这个bean进行拦截--> <bean class="com.happyheng.aop.Servant"></bean> <bean id="happyheng" class="com.happyheng.entity.People"></bean> </beans>
public static void main(String[] args) {
ApplicationContext ctx = new ClassPathXmlApplicationContext(APPLICATION_XML);
People happyheng = (People)ctx.getBean("happyheng");
happyheng.eat();
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有