首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Aspect未被调用

Aspect未被调用
EN

Stack Overflow用户
提问于 2020-07-08 18:35:56
回答 1查看 89关注 0票数 0

我正在做一个简单的项目,在这个项目中我想使用方面。我已经创建了一个具有我的方面的jar (代码如下)

代码语言:javascript
复制
package com.example.aop.logging.aspect;

import java.util.Arrays;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class MyAspect {

    @Before("@annotation(com.example.aop.logging.aspect.Loggable)")
    public void before(JoinPoint joinPoint) {
        System.out.print("***********Before************" + joinPoint.getSignature().getName() + " called with param -> "
                + Arrays.toString(joinPoint.getArgs()));
    }
}

下面是我的Loggable注解

代码语言:javascript
复制
package com.example.aop.logging.aspect;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Loggable {

}

我想将这个jar包含在另一个spring boot项目中,该项目包含我的apis

代码语言:javascript
复制
package com.example.server.controller;

import org.apache.log4j.Logger;

import com.example.aop.logging.aspect.Loggable;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class CreateController {

    private static final Logger LOGGER = Logger.getLogger(CreateController.class);
    
    @Loggable
    @CrossOrigin(origins = "*", allowedHeaders = "*")
    @PostMapping("/create/{userId}")
    public Topic create(@PathVariable String userId) {
        
        LOGGER.debug("Inside createTopic -3 :::" );     
    }   
}

方面没有被调用,您能帮助一下吗?

EN

回答 1

Stack Overflow用户

发布于 2020-07-08 20:32:44

谢谢R.G.问题出在ComponentScan

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62792866

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档