springboot configure some pit AOP encountered (using annotations)

Some read some recent online blog about SpringAOP and found that they are not written especially for me this novice. So I sum up in this, and gives part of the code and screenshots, development tools and environment are as follows:
the development environment: jdk1.8
development tools: idea, maven

  1. The introduction of dependence:
		<!-- aop -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-aop</artifactId>
        </dependency>
        <!-- @Aspect-->
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
        </dependency>

Here Insert Picture Description

  1. Configuration application.properties

Some blog is configured in @SpringBootApplication startup file (in personal like configuration in application.properties)

> #AOP
spring.aop.proxy-target-class=true
spring.aop.auto=true

Here Insert Picture Description

  1. AOP interceptor class configuration

@Before (value = "execution (public * com.zijing.school.controller.UserController.userRegister (...))") in userRegister (...) two. "" Parameter represents the user pass over

@Component
@Aspect
public class UserAspect {
    private final Log log = LogFactory.getLog(UserAspect.class);

    @Before(value = "execution(public * com.zijing.school.controller.UserController.userRegister(..))")
    public void doBeforeRegister(JoinPoint joinPoint) {
        log.info(" 检查是否已经注册");
        Object[] obj = joinPoint.getArgs();
        for (Object argItem : obj) {
            System.out.println("---->now-->argItem:" + argItem);
            log.info(argItem + "");
//            if (argItem instanceof ParamVO) {
//                ParamVO paramVO = (ParamVO) argItem;
//                paramVO.setInputParam("666666");
//            }
//            System.out.println("---->after-->argItem:" + argItem);
        }
    }
}

On 2020/01/20, finished! Did not get demo, Kazakhstan will hold the connection address.

Released five original articles · won praise 0 · Views 807

Guess you like

Origin blog.csdn.net/qq_41237503/article/details/104048441