Spring AOP无法用于@Around

时间:2018-05-16 12:33:20

标签: spring spring-mvc spring-boot spring-security spring-aop

我目前正在研究AOP,但有些AOP无法正常工作,@around在特定控制器上执行之后和之前都没有调用。问题是我的代码。

//我的控制器

package com.rest.controllers;
class ManCon{
@PostMapping(EndPointReferrer.UPDATE_DEALER_SCHEME_MAPPING_DETAILS)
    public ResponseEntity<BaseResponse> updateDealerSchemeMappingDetails(
            @RequestBody @NotNull @Valid Myclass obj){
    return null;  
   }

}

//配置

@Configuration
@EnableAspectJAutoProxy(proxyTargetClass = true)
@ComponentScan(basePackages = {"com.aop"})
public class AOPConfiguration {

    @Bean(autowire = Autowire.BY_TYPE)
    public SchemeMappingPortalAspect schemeMappingPortalAspect(){ return new SchemeMappingPortalAspect(); }

}

//纵横

@Aspect
public class SchemeMappingPortalAspect {

    private static final org.slf4j.Logger logger = LoggerFactory.getLogger(SchemeMappingPortalAspect.class);

    @Pointcut("execution(* com.rest.controllers.ManCon.updateDealerSchemeMappingDetails(..))")
    public void schemeMappingPointcut(){
    }

    /*
    * This is used for scheme mapping portal loging
    * */
    @Around(value = "schemeMappingPointcut()")
    public Object loggingSchemePortalDetail(ProceedingJoinPoint joinPoint) throws Throwable{
        logger.debug("-------------------------");
        logger.debug("In before calling");
        logger.debug("-------------------------");
        Object o=null;
        try {
            o= joinPoint.proceed();
            System.out.println("JSON::"+ new Gson().toJson(o));
        }catch (Exception e){
            e.printStackTrace();
        }
        logger.debug("-------------------------");
        logger.debug("In After Calling");
        logger.debug("-------------------------");
        return o;
    }

}

0 个答案:

没有答案