Java spring@Aspect无法与招摇2配合使用

Java spring@Aspect无法与招摇2配合使用,java,swagger,spring-aop,aspect,Java,Swagger,Spring Aop,Aspect,pom.xml版本信息: springfox-swaggger2:2.5.0 大摇大摆核心:1.5.10 springfox招摇过市用户界面:2.6.1 springboot:1.5.3 我有一个关于斯威格2和springboot的项目 没有@Aspect的项目代码运行得很好 public interface TestApi { WfExecution test(Long temp); } @Api(value = "TestAPI") @RequestMapping(value

pom.xml版本信息:

  • springfox-swaggger2:2.5.0
  • 大摇大摆核心:1.5.10
  • springfox招摇过市用户界面:2.6.1
  • springboot:1.5.3
我有一个关于斯威格2和springboot的项目

没有@Aspect的项目代码运行得很好

public interface TestApi {
    WfExecution test(Long temp);
}


@Api(value = "TestAPI")
@RequestMapping(value = "/test")
@RestController
public class TestApiImpl implements TestApi {

    @Override
    @RequestMapping(value = "/test")
    @ApiOperation(value = "", notes = "", produces = MediaType.APPLICATION_JSON)
    public WfExecution test(@ApiParam(value = "", required = true) @RequestParam(required = true, value = "temp")
                                        Long temp) {
        return new WfExecution();
    }
}
正确的结果是:

但是当我添加下面的代码时,swagger ui并没有显示测试api impl

@Aspect
@Component
public class LoggerAop {
    @Before("execution(* com.XXX.controller.impl.TestApiImpl.*(..))")
    public void doBeforeAdvice(JoinPoint joinPoint){
            System.out.println("XXX");
    }
}
错误结果:

招摇过市和春季AOP之间有冲突吗?

@egg

我设置了类似的项目,面临着同样的问题

在@enableAspectProxy注释中将proxyTargetClass属性设置为true后,问题得到了解决

@enableSpectJautoproxy(proxyTargetClass=true)

仅当我们使用控制器的接口时,才会出现此问题

引用Java文档中的EnableSpectProxy属性的用法

用户可以使用以下命令控制为{@code FooService}创建的代理的类型: {@link#proxyTargetClass()}属性。下面启用CGLIB样式的“子类” 代理,而不是默认的基于接口的JDK代理方法


这个答案是给那些仍然面临这个问题的人的 @方面基本上是一个过滤器。如果排除swagges资源,它将开始工作

你可以用

  @Pointcut("within(com..*..*Controller)")
  @Pointcut("within(com..*..*Service)")

因此,它将只扫描那些从com开始的包…

我使用SpringAOP和Springfox。在webUi中,我发现webUi中有一个代理类。其方法与TestApi类的方法相同。