說我有Spring AOP的配置一樣我該如何(或者應該)將Aspect Advice應用於動態代理?
@Configuration
@EnableAspectJAutoProxy
@ComponentScan
class Config { ... }
和我有一些接口,ProxiableInterface
。我
ProxiableInterface pi = (ProxiableInterface) Proxy.newProxyInstance(
applicationContext.getClassLoader(),
new Class[] {ProxiableInterface.class},
(proxy, method, args) -> { ... });
實現它我也有一個看點:
@Aspect
class SomeAspect {
@Around("execution(package.ProxiableInterface.*)")
Object doStuffAround(ProceedingJoinPoint pjp) { ... }
}
當我呼籲ProxiableInterface
的方法,該方法看點不會被調用。有沒有一種方法來「登記」這個代理服務器,以便它被建議?我可以簡單地按照代理的InvocationHandler中的建議進行操作,但這會導致代碼重複,因爲此建議已經適用於代碼的其他區域。
jic,也許你不需要這麼複雜的界面。而且由於你用new實例化,它不是代理,所以當然不會調用它。只是找到一些方法來得到它與豆,你應該沒問題 – Sarief