当前位置:首页 > java > 正文内容

java spring切面编程

root2年前 (2023-12-01)java3872
package com.example.test.config;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;
@Component
@Aspect
public class AnnotationPointcut {
   @Before("execution(* com.example.test.job..*(..))")
   public void before(){
       System.out.println("========方法执行前=========");
   }


   @After("execution(* com.example.test.job..*(..))")
   public void after(){
       System.out.println("========方法执行后=========");
   }

   @Around("execution(* com.example.test.server.Impl.*(..))")
   public void around(ProceedingJoinPoint pjp) throws Throwable {
       System.out.println("---------环绕前---------");
       pjp.proceed();
       System.out.println("---------环绕后---------");
   }
}

Aspect切面注解,声明是一个切面类

Component  注入spring框架中


Before、After 这里注解是对指定的类方法执行的时候执行方法内容


扫描二维码推送至手机访问。

版权声明:本文由一叶知秋发布,如需转载请注明出处。

本文链接:https://zhiqiu.top/?id=255

分享给朋友:

相关文章

spring程序开发步骤

1、导入Spring开发的基本包坐标2、编写Dao接口和实现类3、创建Spring核心配置文件4、在Spring配置文件中配置xxDaoImpl5、使用Spring的API获取Bean实例...

java @Bean 注解

Spring的@Bean注解用于告诉方法,产生一个Bean对象,然后这个Bean对象交给Spring管理。产生这个Bean对象的方法Spring只会调用一次,随后这个Spring将会将这个Bean对象放在自己的IOC容器中。SpringIO...

java-Springboot的几个重要注解@controller、@service、 @repository、@component

1、@controller 控制器(注入服务)用于标注控制层,相当于struts中的action层2、@service 服务(注入dao)用于标注服务层,主要用来进行业务的逻辑处理3、@repository(实现dao访问)用于标注数据访问...

java invoke 的反射用法 及参数传递

import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; public class&nbs...

java 处理json 字符串

假设有一个实体类public class User{   private int id;   private String name;&...

java springboot @ApiModelProperty用法

@ApiModelProperty()用于方法,字段; 表示对model属性的说明或者数据操作更改 value–字段说明 name–重写属性名字 dataType–重写属性类型 required–是否...