@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>