when to use this(obj) & target(obj) to select join points ? whats different ?
PCD target() and this() intercepts any Spring managed beans public methods execution. I wonder is there any difference between those. Or its just you can do the same thing in multiple ways ?
@Aspect
public class MyAspect {
//@Before("target(proxyObj)")
@Before("this(proxyObj)")
public void applyBeforeAdvice(Object proxyObj) {
System.out.println("This is the advice from MyAspect ");
System.out.println("[From Aspect]" + proxyObj.getClass().getCanonicalName());
}
}
@ContextConfiguration("classpath:my/aspect/aspects-config.xml")
@RunWith(SpringJUnit4ClassRunner.class)
public class AspectTest {
@Autowired
private SomeService myService;
@Autowired
private AnotherService anotherService;
@Test
public void test() {
anotherService.myAnotherServiceMethod();
myService.anotherServiceMethod();
myService.myServiceMethod();
}
}