Spring boot 未调用Spring boot 1.5.12特性

Spring boot 未调用Spring boot 1.5.12特性,spring-boot,aop,Spring Boot,Aop,我知道Stackoverflow中有很多类似的问题,但没有一个对我有帮助 我有一个这样的控制器: com.mypkg.controller; @RestController public class MyController { @RequestMapping(method = RequestMethod.POST, ...... public ResponseEntity<?> MyEndpoint(myParams) { return this.my

我知道Stackoverflow中有很多类似的问题,但没有一个对我有帮助

我有一个这样的控制器:

com.mypkg.controller;

@RestController
public class MyController {

  @RequestMapping(method = RequestMethod.POST,
   ......
  public ResponseEntity<?> MyEndpoint(myParams) {
      return this.myMethod(myParams, "myString");
  }

  public ResponseEntity<?> myMethod(myParams, String myString){
     //do something
     return myReponseEntity
  }
}
每次调用MyEndpoint(抛出RESTAPI)时,都会调用函数
endpointAround


问题是周围的第二个问题。它不叫。每次执行
MyEndpoint
时,我都需要调用一个方法,每次
MyEndpoint
调用
myMethod

时,我都需要调用另一个方法。问题是,您的方法
myMethod
是从其他方法中直接调用的,而不是作为
someSpringBean.myMethod


spring的工作方式是包装您的任何bean,然后在“包装”上它可以执行所有方面或其他与spring相关的内容。当您从同一类中的另一个方法调用一个方法时,您不需要进行包装,因此与方面相关的事情不会发生

问题是您的方法
myMethod
是从另一个方法中直接调用的,而不是作为
someSpringBean.myMethod


spring的工作方式是包装您的任何bean,然后在“包装”上它可以执行所有方面或其他与spring相关的内容。当您从同一个类中的另一个方法调用一个方法时,您没有经过包装,因此与方面相关的事情不会发生

您只是错过了一些代码。让我们使用下面的代码片段,它将工作。 使用此
com.mypkg.controller.MyController.myMethod
代替
com.mypkg.controller.myMethod

控制器

com.mypkg.controller

@RestController
public class MyController {

  @RequestMapping(method = RequestMethod.POST,
   ......
  public ResponseEntity<?> MyEndpoint(myParams) {
      return this.myMethod(myParams, "myString");
  }

  public ResponseEntity<?> myMethod(myParams, String myString){
     //do something
     return myReponseEntity
  }
}
@Aspect
@Component
@Slf4j
public class MyAspect {
    @Around("execution(* com.mypkg.controller.MyController.MyEndpoint(..))  && args(..,aParam)")
    public ResponseEntity<?> endpointAround(ProceedingJoinPoint joinPoint, String aParam) throws Throwable {
        // I am working fine
        // do something
        return 
   }

    @Around("execution(* com.mypkg.controller.MyController.myMethod(..))  && args(..,myString)")
    public ResponseEntity<?> myMethodAround(ProceedingJoinPoint joinPoint, String myString) throws Throwable {
        // **** I AM NOT CALLED****
        // do something
        // return ...
   }
}
@RestController
公共类MyController{
@RequestMapping(method=RequestMethod.POST,
......
公共响应MyEndpoint(myParams){
返回这个.myMethod(myParams,“myString”);
}
公共响应属性myMethod(myParams、字符串myString){
//做点什么
返回MyResponseEntity
}
}
和在方面

com.mypkg.controller

@RestController
public class MyController {

  @RequestMapping(method = RequestMethod.POST,
   ......
  public ResponseEntity<?> MyEndpoint(myParams) {
      return this.myMethod(myParams, "myString");
  }

  public ResponseEntity<?> myMethod(myParams, String myString){
     //do something
     return myReponseEntity
  }
}
@Aspect
@Component
@Slf4j
public class MyAspect {
    @Around("execution(* com.mypkg.controller.MyController.MyEndpoint(..))  && args(..,aParam)")
    public ResponseEntity<?> endpointAround(ProceedingJoinPoint joinPoint, String aParam) throws Throwable {
        // I am working fine
        // do something
        return 
   }

    @Around("execution(* com.mypkg.controller.MyController.myMethod(..))  && args(..,myString)")
    public ResponseEntity<?> myMethodAround(ProceedingJoinPoint joinPoint, String myString) throws Throwable {
        // **** I AM NOT CALLED****
        // do something
        // return ...
   }
}
@方面
@组成部分
@Slf4j
公共类MyAspect{
@大约(“execution(*com.mypkg.controller.MyController.MyEndpoint(..)&&args(..,aParam)”)
公共响应endpointAround(ProceedingJoinPoint、String aParam)抛出Throwable{
//我工作得很好
//做点什么
返回
}
@大约(“execution(*com.mypkg.controller.MyController.myMethod(..)&&args(..,myString)”)
public ResponseEntity myMethodAround(ProceedingJoinPoint,String myString)抛出Throwable{
//****我没有接到电话****
//做点什么
//返回。。。
}
}

您刚刚错过了包路径。您的方法路径应该是这样的
…springbean.method
您刚刚错过了一些代码。让我们使用下面的代码片段,它可以工作。 使用此
com.mypkg.controller.MyController.myMethod
代替
com.mypkg.controller.myMethod

控制器

com.mypkg.controller

@RestController
public class MyController {

  @RequestMapping(method = RequestMethod.POST,
   ......
  public ResponseEntity<?> MyEndpoint(myParams) {
      return this.myMethod(myParams, "myString");
  }

  public ResponseEntity<?> myMethod(myParams, String myString){
     //do something
     return myReponseEntity
  }
}
@Aspect
@Component
@Slf4j
public class MyAspect {
    @Around("execution(* com.mypkg.controller.MyController.MyEndpoint(..))  && args(..,aParam)")
    public ResponseEntity<?> endpointAround(ProceedingJoinPoint joinPoint, String aParam) throws Throwable {
        // I am working fine
        // do something
        return 
   }

    @Around("execution(* com.mypkg.controller.MyController.myMethod(..))  && args(..,myString)")
    public ResponseEntity<?> myMethodAround(ProceedingJoinPoint joinPoint, String myString) throws Throwable {
        // **** I AM NOT CALLED****
        // do something
        // return ...
   }
}
@RestController
公共类MyController{
@RequestMapping(method=RequestMethod.POST,
......
公共响应MyEndpoint(myParams){
返回这个.myMethod(myParams,“myString”);
}
公共响应属性myMethod(myParams、字符串myString){
//做点什么
返回MyResponseEntity
}
}
和在方面

com.mypkg.controller

@RestController
public class MyController {

  @RequestMapping(method = RequestMethod.POST,
   ......
  public ResponseEntity<?> MyEndpoint(myParams) {
      return this.myMethod(myParams, "myString");
  }

  public ResponseEntity<?> myMethod(myParams, String myString){
     //do something
     return myReponseEntity
  }
}
@Aspect
@Component
@Slf4j
public class MyAspect {
    @Around("execution(* com.mypkg.controller.MyController.MyEndpoint(..))  && args(..,aParam)")
    public ResponseEntity<?> endpointAround(ProceedingJoinPoint joinPoint, String aParam) throws Throwable {
        // I am working fine
        // do something
        return 
   }

    @Around("execution(* com.mypkg.controller.MyController.myMethod(..))  && args(..,myString)")
    public ResponseEntity<?> myMethodAround(ProceedingJoinPoint joinPoint, String myString) throws Throwable {
        // **** I AM NOT CALLED****
        // do something
        // return ...
   }
}
@方面
@组成部分
@Slf4j
公共类MyAspect{
@大约(“execution(*com.mypkg.controller.MyController.MyEndpoint(..)&&args(..,aParam)”)
公共响应endpointAround(ProceedingJoinPoint、String aParam)抛出Throwable{
//我工作得很好
//做点什么
返回
}
@大约(“execution(*com.mypkg.controller.MyController.myMethod(..)&&args(..,myString)”)
public ResponseEntity myMethodAround(ProceedingJoinPoint,String myString)抛出Throwable{
//****我没有接到电话****
//做点什么
//返回。。。
}
}

您刚刚错过了包路径。您的方法路径应该是这样的
…springbean.method

谢谢您,我没有错过包路径,我只是忘了在这里添加它。很抱歉。正如我说的那样,
endpointAround
被调用并具有相同的执行definition@Fabry你的方法怎么会被调用,我没有查看任何映射,因为对我来说,上面的代码片段正在正确执行。谢谢,我没有错过包路径,我只是忘了在这里添加它。对此表示抱歉。正如我所说的,调用了
endpointAround
,并具有相同的执行definition@Fabry你的myMethod是如何被调用的。我没有看到任何映射,因为对我来说,上面的代码片段pet被正确执行。See也有可能重复,都是相同的问题。我已经回答了这么多次,并且有很好的记录…没有冒犯的意思。See也有可能重复,都是相同的问题。我已经回答了这么多次,并且有很好的记录…没有冒犯的意思。我解决了它,将我的方法导出到服务,现在它工作了我解决了它,将myMethod导出到服务中,现在它工作了