使用注解实现 aop | 学习笔记

简介: 快速学习使用注解实现 aop

开发者学堂课程【Java Web 开发系列课程:Spring 框架入门使用注解实现 aop】学习笔记,与课程紧密联系,让用户快速学习知识。

课程地址:https://developer.aliyun.com/learning/course/538/detail/7347


使用注解实现 aop

内容简介:

一、自定义类来实现

二、通过注解来实现

 

一、自定义类来实现

第二种方式实现 aop:自定义类来实现

代码如下:

Log java

public class Log{

public void before(){

System.out.println("-----方法执行前---");

public void after(){

System.out.println("----方法执行后---);

业务类不改变

配置文件

class="cn.sxt.service.impl.UserServiceImpl"/>

cn.sxt.service.impl.*.*(..))”id="pointcut"/>

pointcut-ref="pointcut"/>

二、通过注解来实现

第三种实现方法:通过注解来实现

Logjava

public class Log {

@Before("execution(* cn.sxt.service,impl.."(..))")

public void before(){

System.out.println("---方法执行前---");

}

@After(*execution(*cn.sxt.service.impl...(..))")

public void after()

System.out.println("-方法执行后");

@Around("execution(* cn.sxt.service,impl.**(..))")

public obiect aroud(ProceedingjoinPoint ip) throws Throwablef

System.out.println("环绕前");

System.out.println(*签名:"+jp.getSignature());

//执行目标方法

Object result = jp.proceed();

System.out.println("环绕后");

return result;

}

}

配置文件

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.xs

d

http://www.springframework.org/schema/aop

http://www.springframework.org/schema/aop/spring-aop.xsd"

class="cn.sxt.service.impl.UserServiceImpl"/>

相关文章
|
2月前
|
XML Java 数据库
Spring5入门到实战------10、操作术语解释--Aspectj注解开发实例。AOP切面编程的实际应用
这篇文章是Spring5框架的实战教程,详细解释了AOP的关键术语,包括连接点、切入点、通知、切面,并展示了如何使用AspectJ注解来开发AOP实例,包括切入点表达式的编写、增强方法的配置、代理对象的创建和优先级设置,以及如何通过注解方式实现完全的AOP配置。
|
4月前
|
XML 安全 Java
Spring高手之路19——Spring AOP注解指南
在本文中,我们将深入探索Spring AOP(面向切面编程)的核心概念及其在现代Spring应用中的实际应用。从基本的注解使用到复杂的切面配置,本文将一步步指导你如何利用Spring AOP提升代码的模块化,帮助你在Spring开发路上更进一步。
61 3
Spring高手之路19——Spring AOP注解指南
|
4月前
|
Java Spring 容器
基于注解的Aop开发,实现aop快速入门,基于注解的AOP开发
基于注解的Aop开发,实现aop快速入门,基于注解的AOP开发
|
3月前
|
分布式计算 Java MaxCompute
详解 Java 限流接口实现问题之在Spring框架中使用AOP来实现基于注解的限流问题如何解决
详解 Java 限流接口实现问题之在Spring框架中使用AOP来实现基于注解的限流问题如何解决
|
5月前
|
Java 开发者 Spring
面向切面编程(SpringAOP)、通过注解实现AOP代码、AOP的工作流程
面向切面编程(SpringAOP)、通过注解实现AOP代码、AOP的工作流程
60 1
面向切面编程(SpringAOP)、通过注解实现AOP代码、AOP的工作流程
|
4月前
|
监控 Java Spring
自定义注解+AOP切面日志+源码
自定义注解+AOP切面日志+源码
37 1
|
3月前
|
容器
springboot-自定义注解拦截ip aop和ioc
springboot-自定义注解拦截ip aop和ioc
|
4月前
|
Java Spring
自定义注解+AOP
自定义注解+AOP
40 1
|
4月前
|
XML Java 数据格式
Spring5系列学习文章分享---第三篇(AOP概念+原理+动态代理+术语+Aspect+操作案例(注解与配置方式))
Spring5系列学习文章分享---第三篇(AOP概念+原理+动态代理+术语+Aspect+操作案例(注解与配置方式))
37 0
|
4月前
|
Java Maven Spring
Spring中AOP最简单实例-@注解形式
Spring中AOP最简单实例-@注解形式
36 0