
本文共 3522 字,大约阅读时间需要 11 分钟。
OOP���AOP���������
OOP���������������������������AOP���������������������������������������������������������������������OOP������������������������������������������������AOP������������������������������������������������������������������������������������������������
���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
���������������������
���Spring������������������������������AOP������������������������������������������������������������������
<.component-scan base-package="com.springboot">
@Repositorypublic interface StudentDao { void insert(Student student); void delete(int id);}@Repositorypublic class StudentDaoImpl implements StudentDao { @Override public void insert(Student student) { System.out.println("������������������"); } @Override public void delete(int id) { System.out.println("������������������"); }}
@Component@Aspectpublic class CheckSecurityAop { @Order(1) @Before("execution(* com.springboot.StudentDaoImpl.delete(..))") public void checkSecurity() { System.out.println("������������������"); }}
public class Client { public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml"); StudentDao studentDao = context.getBean("studentDaoImpl", StudentDao.class); studentDao.delete(1); }}
@Before���@After���������������
- @Before������������������������������������������������������������������������������������������������������������������������������������������������������������������
- @After������������������������������������������������������������������������������������������������������������������������������������������������@After���������������������
- @Around���������������������������@Before���@After���@AfterReturning���@AfterThrowing���������������������������������������������������������
- @AfterReturning���������������������������������������������������������������������������������������������������������������������������������
- @AfterThrowing���������������������������������������������������������������������������������������������������������
������������@Around���������������
@Around("execution(* com.springboot.ArithmeticCalculator.add(int,int))")public Object aroundMethod(ProceedingJoinPoint joinPoint) { try { Object result = joinPoint.proceed(); return result; } catch (Throwable e) { throw new RuntimeException("������������������", e); } finally { System.out.println("������������������"); }}
������������
���������������������������������������������������������������result������������������������������������������������������������������������������������null������������������������������������������������������������try...catch������������������������������������������������������������������������null���
������������������������������������@AfterThrowing��������������������������������������������������������������� throwable ���������������������������
������������������AOP������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
发表评论
最新留言
关于作者
