I have to apply Spring AOP for legacy code without changing anything in the existing code. There is no bean concept and the objects are created using new keyword, so no scope of using applicationContext.getBean("beanName"). Also the pointcuts will be taken as input from end user and there will be a common aspect class.
For eg.
package package1;
public class Demo1 {
public void method1()
{
System.out.println("From method1");
}
public void method2()
{
System.out.println("From method2");
}
}
package package2;
public class Demo2 {
public void method3()
{
System.out.println("From method3");
}
public void method4()
{
System.out.println("From method4");
}
}
package aspects;
public class SpringAspect {
public void beforeAdvice(JoinPoint jointPoint)
{
System.out.println("Before method : "+jointPoint.getSignature());
}
}
Pointcuts taken as input from end user are as follows and their before advisor method is beforeAdvice() from aspects.SpringAspect class : execution(* package1.Demo1.method1(..)) execution(* package2.Demo2.method4(..))
Also if it is not possible using Spring AOP, how can I use AspectJ during runtime for the same.