我正在做一个简单的项目,在这个项目中我想使用方面。我已经创建了一个具有我的方面的jar (代码如下)
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注解
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
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 :::" );
}
}方面没有被调用,您能帮助一下吗?
发布于 2020-07-08 20:32:44
谢谢R.G.问题出在ComponentScan
https://stackoverflow.com/questions/62792866
复制相似问题