私のSpringコンテキストファイルには、次のようなものがあります。
<bean id="userCheck" class="a.b.c.UserExistsCheck"/>
<aop:config>
<aop:aspect ref="userCheck">
<aop:pointcut id="checkUser"
expression="execution(* a.b.c.d.*.*(..)) && args(a.b.c.d.RequestObject)"/>
<aop:around pointcut-ref="checkUser" method="checkUser"/>
</aop:aspect>
</aop:config>
abcUserExistsCheckは次のようになります。
@Aspect
public class UserExistsCheck {
@Autowired
private UserInformation userInformation;
public Object checkUser(ProceedingJoinPoint pjp) throws Throwable {
int userId = ... //get it from the RequestObject passed as a parameter
if (userExists(userId)) {
return pjp.proceed();
} else {
return new ResponseObject("Invalid user);
}
}
そして、このようなもので傍受されているクラスは次のようになります。
public class Klazz {
public ResponseObject doSomething(RequestObject request) {...}
}
これは機能します。UserExistCheckは、呼び出しがKlazzに渡される前に必要に応じて実行されます。問題は、これが私がそれを機能させる唯一の方法であるということです。コンテキストファイルの代わりに注釈を使用してこれを機能させることは、私の小さな頭脳にとってはやりすぎのようです。では...UserExistsCheckとKlazzのメソッドにどの程度正確に注釈を付ける必要がありますか?そして、私はまだ何か他のものが必要ですか?別のクラス?コンテキストファイルにまだ何かありますか?