spring中基于XML的AOP配置步骤
发布日期:2021-05-10 19:06:23 浏览次数:22 分类:精选文章

本文共 1837 字,大约阅读时间需要 6 分钟。

Spring���������XML���AOP������������������

������������������Spring AOP

Spring AOP������������������������������AOP���������������XML���������������������������������������������������������������������������������������

������������������

1. ������Spring������������

������������ bean.xml ������������������������

2. ���������������

������AccountServiceImpl������������AOP������������

public class AccountServiceImpl implements IAccountService {
@Override
public void saveAccount() {
System.out.println("���������������");
}
@@Override
public void updateAccount(int i) {
System.out.println("���������������" + i);
}
@Override
public int deleteAccount() {
System.out.println("���������������");
return 0;
}
}

3. ������������

���AOPTest���������������

public class AOPTest {
public static void main(String[] args) {
ApplicationContext ac = new ClassPathXmlApplicationContext("bean.xml");
IAccountService as = (IAccountService) ac.getBean("accountService");
as.saveAccount();
as.updateAccount(1);
as.deleteAccount();
}
}

������������������������

1. bean.xml������������

  • <?xml version="1.0" encoding="UTF-8"?>���������XML���������������
  • <beans>���������Spring���bean���������������
  • <bean>���������������bean������������id��� bean ���������������class������������������

2. AOP������

  • <aop:config>���������AOP������������
  • <aop:aspect id="logAdvice" ref="logger">������������������������ref="logger"���������������������
  • <aop:before method="printLog" pointcut="execution(* com.itheima.service.impl.*.*(..))" />���
    • method���������������������������������
    • pointcut������������������������������������������������������������
上一篇:Spring Boot 入门——Spring Boot 简介||微服务简介
下一篇:基于子类的动态代理

发表评论

最新留言

网站不错 人气很旺了 加油
[***.192.178.218]2025年04月17日 07时03分18秒