我试图在Play Framework中对Global.java提出建议。
我无法从spring容器中获取bean的原因是因为这个Global.java正在由Play Framework引导,我无法手动替换它的实例。
我能想到的两种可能的解决方案:
autowireBean(..)
的方法,不仅可以设置。{
autowirings也提供建议。这是我的代码段:
@Component( "global" )
public class Global {
private ApplicationContext ctx;
@Override
public void onStart(Application app) {
this.ctx = new ClassPathXmlApplicationContext( "spring-config.xml" );
this.ctx.getAutowireCapableBeanFactory().autowireBean( this );
}
@Override
public Action<?> onRequest(Request req, Method actionMethod)
return ....
}
}
@Aspect
public class AspectDemo {
@Around( "execution(* Global.onRequest(..))" )
public Object myAround(ProceedingJoinPoint jp) throws Throwable
{
System.out.println( "advising around start");
Object obj = jp.proceed();
// do something about the obj...
System.out.println( "advising around end");
return obj;
}
}