Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring AOP方面未执行_Java_Spring_Aop_Aspectj - Fatal编程技术网

Java Spring AOP方面未执行

Java Spring AOP方面未执行,java,spring,aop,aspectj,Java,Spring,Aop,Aspectj,我想记录我的服务方法的执行时间。 我认为AOP是一种简单的方法,所以我写了一个方面: @Aspect public class ServiceLogAdviceAspect { private static Logger LOG = LoggerFactory.getLogger(ServiceLogAdviceAspect.class); @Around("execution(* com.j1.**.service.*(..))") public Object doB

我想记录我的服务方法的执行时间。
我认为AOP是一种简单的方法,所以我写了一个方面:

@Aspect
public class ServiceLogAdviceAspect {
    private static Logger LOG = LoggerFactory.getLogger(ServiceLogAdviceAspect.class);

    @Around("execution(* com.j1.**.service.*(..))")
    public Object doBasicProfilingTime(ProceedingJoinPoint joinPoint) throws Throwable {
        String methodName = joinPoint.getSignature().getName();
        Object target = joinPoint.getTarget();
        long start = System.currentTimeMillis();
        Object retVal = joinPoint.proceed();
        long end = System.currentTimeMillis();
        LOG.error(String.format("Invoke [%s$%s] Takes %d ms", target.getClass().getCanonicalName(), methodName, (end - start)));
        return retVal;
    }
}
和Spring配置:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"
        default-autowire="byName">
    <aop:aspectj-autoproxy/>
    <bean id="logAdviceAspect" 
        class="com.j1.soa.common.aspect.ServiceLogAdviceAspect"></bean>
</beans>
然后在客户端定义它

@Autowired
private GoodsDetailService goodsDetailService;
以及使用它

GoodsDetailDto goodsDetailDto = new GoodsDetailDto();
goodsDetailDto.setGoodsId(NumericUtil.parseLong(goodsId));
goodsDetailDto.setProductId(NumericUtil.parseInt(productId));
goodsDetailDto.setSiteType(SiteType.MOBILE);

ServiceMessage<GoodsDetailDto> detailResult = goodsDetailService
                .getGoodDetail(goodsDetailDto);
GoodsDetailDto GoodsDetailDto=新的GoodsDetailDto();
goodsDetailDto.setGoodsId(NumericUtil.parseLong(goodsId));
goodsDetailDto.setProductId(NumericUtil.parseInt(productId));
goodsDetailDto.setSiteType(SiteType.MOBILE);
ServiceMessage detailResult=goodsDetailService
.getGoodDetail(goodsDetailDto);

您应该在



请共享getGoodDetail()方法类的定义位置以及它在spring上下文中的定义方式显示调用的代码
getGoodDetail
。首先,您如何调用此方法?其次,您的切入点是错误的,应该是执行(*com.j1..service.*(..)。我注意到,您使用的名称空间来自混合版本,最早可以追溯到Spring 2.0,这与现代Spring很难识别。首先使用一致的版本,最好是4。
GoodsDetailDto goodsDetailDto = new GoodsDetailDto();
goodsDetailDto.setGoodsId(NumericUtil.parseLong(goodsId));
goodsDetailDto.setProductId(NumericUtil.parseInt(productId));
goodsDetailDto.setSiteType(SiteType.MOBILE);

ServiceMessage<GoodsDetailDto> detailResult = goodsDetailService
                .getGoodDetail(goodsDetailDto);
<aop:aspectj-autoproxy>
    <aop:include name="logAdviceAspect"/>
</aop:aspectj-autoproxy>