我有一个方面的建议,可以跟踪用@Service 注释的类的执行。该代码目前正在运行,但我想将其更改为跟踪控制器上的 REST 端点,而不是自动连接的服务。这是代码:
@Aspect
public class AuditingAspect
{
@Pointcut(
//TODO Change pointcut from public methods in Services to REST endpoints in Controllers
"execution(public * my.base.package..*.*(..))" //Must be in package
//+ " && @within(org.springframework.stereotype.Service)" //Has to be a service
+ " && @within(org.springframework.stereotype.Controller)" //Has to be a controller
)
public void auditLoggingPointCut() {
//no op
}
@Around(value ="auditLoggingPointCut()")
public Object logAround(final ProceedingJoinPoint joinPoint) throws Throwable
{
System.out.println("Exection");
returnVal = joinPoint.proceed();
// Now Do The After Logging Part
afterReturningLog(joinPoint, returnVal) ;
return returnVal;
}
private void afterReturningLog(final JoinPoint joinPoint, final Object returnValue)
{
System.out.println("Exiting");
}
}
当我将“内部”从@Service 更改为@Controller 时,我看不到建议的任何输出,但该方法在从 URL 访问时执行。忽略执行的控制器有什么不同?
控制器类如下所示:
@Controller
public class CaseReferralEndpoints {
@Autowired
CaseReferralFacade caseReferralFacade;
@RequestMapping(value="/backgroundcheck/getcasereferrals", method = RequestMethod.GET)
@ResponseBody
public List<CaseReferralSection> getCaseReferrals(@RequestParam("caseID") Long caseID) {
return caseReferralFacade.getCaseReferrals(caseID);
}
}
这是我的 applicationContext-aop.xml 完整的配置要大得多,但我相信这是最相关的。
<?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.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
<bean class="gov.dhs.uscis.elis2.backend.services.logging.AuditingAspect"/>
<aop:aspectj-autoproxy proxy-target-class="false" />
</beans>