-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi,
I try to integrate Spring AOP in my ZK 6 + Shiro application.
I use BinderComposer+MVVM and I want to intercept Shiro Authorization exception from an aspect.
The problem is the creation and init of VieModel. If I create ViewModel from Spring, Zk not found Annotations (@Command @Init...) in the Proxy AOP object. If I create ViewModel from ZK, the class is out of Spring control.
Can anyone found a solution / workaround to this?
Best Regards
[SOLVED]
after two day of testing I found the solution and I want to share with you.
the trick is very simple: you can instument your tomcat class loader with a context.xml like this:
<Context>
<Loader
loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"
</Loader>
</Context>
this spring class instrument ALL class of your project for AOP. Next with aop.xml you can specify which class or package you want to monitoring:
<aspectj>
<!-- definitions of aspects available to the weaver, and which
ones should be used or not used -->
<aspects>
<aspect name="your.package.aspects.base.MyAspect"/>
</aspects>
<!-- control over the weaver itself and the types that will be
woven -->
<weaver options="-showWeaveInfo">
<include within="your.base.package.viewmodels..*"/>
</weaver>
with this you can monitoring all viewmodels in your package and subpakage, with an aspect class like this
@Apect
public class MyAspect{
@Around("execution(* your.base.package.viewmodels..*(..)) && @annotation(reqPermissions)")
public Object permInterceptor(ProceedingJoinPoint point,RequiresPermissions reqPermissions) throws Throwable{
...
}
}
that's all
I hope it is useful for someone
best regards
Andrea
Hi Andrea,
I tried your solution, but for me it doesn't work. In my applicationContext.xml I added this lines:
<aop:config>
<aop:aspectj>
<!-- definitions of aspects available to the weaver, and which ones should
be used or not used -->
<aop:aspects>
<aop:aspect name="it.hf.gerapweb.spring.LoggingAspect" />
</aop:aspects>
<!-- control over the weaver itself and the types that will be woven -->
<aop:weaver options="-showWeaveInfo">
<aop:include within="it.hf.gerapweb.bind.funzioni..*" />
</aop:weaver>
</aop:aspectj>
</aop:config>
The class LoggingAspect is:
package it.hf.gerapweb.spring;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Aspect
public class LoggingAspect {
private static Logger log = LoggerFactory.getLogger(LoggingAspect.class);
public LoggingAspect() {
log.info("Costruttore");
}
@Around("execution(* it.hf.gerapweb.bind.funzioni..*(..))")
public void invoke() {
log.info("Before");
log.info("After");
}
}
I added spring-instrument-tomcat-4.3.21.RELEASE.jar in my tomcat7 lib and in context.xml:
<Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"></Loader>
Thanks a lot. Nico
Asked: 2013-07-30 10:44:21 +0800
Seen: 26 times
Last updated: Jan 18 '19
Not able to bind Spring beans after zk upgrade
spring + zk @autowired problem
Problem binding values to a composite component
How to access static member field of a class in zul without zscript
How can i load a constant in .zul
MVVM Validator: class not found ? [closed]
MVVM tab box - delay @load until tab pane displayed?
mvvm, load or save with after or before for seach command
how to fire an event when a variable value loaded through VM