最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
在Spring中使用动态代理示例代码
时间:2022-06-29 02:20:56 编辑:袖梨 来源:一聚教程网
本篇文章小编给大家分享一下在Spring中使用动态代理示例代码,文章代码介绍的很详细,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看。
Spring动态代理
定义自定义切面 - diyNodePoint
package com.lxc.diy;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
/**
* @Aspect 标注这个了是一个切面
* @Before("切入点") ===
* @After("切入点") ===
*/
@Aspect
public class diyNotePoint {
@Before("execution(* com.lxc.service.UserServiceImp.*(..))")
public void before() {
System.out.println("前置切面");
}
@After("execution(* com.lxc.service.UserServiceImp.*(..))")
public void after() {
System.out.println("后置切面");
}
}
定义接口 - UserService
package com.lxc.service;
public interface UserService {
public void query();
public void delete();
public void edit();
public void add();
}
重写接口类 - UserServiceImp
package com.lxc.service;
public class UserServiceImp implements UserService{
@Override
public void query() {
System.out.println("query");
}
@Override
public void delete() {
System.out.println("delete");
}
@Override
public void edit() {
System.out.println("edit");
}
@Override
public void add() {
System.out.println("add");
}
}
beans.xml中配置:
测试:
import com.lxc.service.UserService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Test {
public static void main(String[] args) {
ApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");
UserService userService = ctx.getBean("imp", UserService.class);
userService.add();
}
}
输出如下:
相关文章
- 三国志8重制版虚构特典剧本介绍说明 10-30
- 暗喻幻想暗黑法师解锁方法攻略分享 10-30
- 暗喻幻想元素大师解锁方法攻略分享 10-30
- 暗喻幻想地下纳骨堂锁住的门打开方法 10-30
- 暗喻幻想6月22日玛丽亚位置一览 10-30
- 暗喻幻想巫师阿基态解锁方法分享 10-30
