Dear All,
I am having a problem with simple AOP application. Actually I think the proxy of my class does not created. So anybody please guide what is the actually problem and how can I resolve this. I am using Eclipse6 IDE and I added the following jars.
spring-beans.jar
spring-context.jar
spring-core.jar
commons-attributes-api.jar
commons-attributes-comiler.jar
commons-logging.jar
log4j-1.2.14.jar
spring-aop.jar
spring-agent.jar
spring-tomcat-weaver.jar
asm-2.2.3.jar
asm-comons-2.2.3.jar
asm-util-2.2.3.jar
aspectjrt.jar
aspectjweaver.jar
aopalliance.jar
cglib-nodep-2.1_3.jar
jakarta-2.0.8.jar
I found the following Exceptions
my applicationCotext.xml is as followsCode:Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testDao' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Couldn't generate CGLIB subclass of class [class test.TestDao]: Common causes of this problem include using a final class or a non-visible class; nested exception is net.sf.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null Caused by: org.springframework.aop.framework.AopConfigException: Couldn't generate CGLIB subclass of class [class test.TestDao]: Common causes of this problem include using a final class or a non-visible class; nested exception is net.sf.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null Caused by: net.sf.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:237) at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:377) at net.sf.cglib.proxy.Enhancer.create(Enhancer.java:285) at org.springframework.aop.framework.Cglib2AopProxy.getProxy(Cglib2AopProxy.java:196) at org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:110) at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.createProxy(AbstractAutoProxyCreator.java:429) at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:299) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:315) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1181) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:428) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:270) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160) at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:733) at main.SpringMain.main(SpringMain.java:17) Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at net.sf.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:384) at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:219) ... 13 more Caused by: java.lang.SecurityException: class "test.TestDao$$EnhancerByCGLIB$$651400c9"'s signer information does not match signer information of other classes in the same package at java.lang.ClassLoader.checkCerts(Unknown Source) at java.lang.ClassLoader.preDefineClass(Unknown Source) at java.lang.ClassLoader.defineClass(Unknown Source) ... 19 more
my testDao class is as follows...Code:<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> <bean id="testDao" class="test.TestDao" scope="prototype"></bean> <bean id="methodTimingAdvice" class="interceptor.MethodTimingInterceptor"/> <aop:config> <aop:pointcut id="getCountriesPointCut" expression="execution(* test.TestDao.getCountries())"/> <aop:advisor id="methodTimingAdvisor" advice-ref="methodTimingAdvice" pointcut-ref="getCountriesPointCut"/> </aop:config> </beans>
my TimingInteceptor is as followsCode:public TestDao(){ System.out.println("Instance of TestDao is being created"); } @Override public String toString() { return "New Object of TestDao created at ---> "+super.toString(); } public List<String> getCountries(){ //having some db logic } }
Thank you very much in advance for you response.Code:package interceptor; import java.math.BigDecimal; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; import org.apache.commons.lang.time.DateUtils; import org.apache.commons.lang.time.StopWatch; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; public class MethodTimingInterceptor implements MethodInterceptor { final Log log = LogFactory.getLog(getClass()); public Object invoke(final MethodInvocation methodinoInvocation) throws Throwable { Object methodResult = null; final StopWatch stopWatch = new StopWatch(); stopWatch.start(); try{ methodResult = methodinoInvocation.proceed(); }finally{ stopWatch.stop(); } final long milis = stopWatch.getTime(); final BigDecimal seconds = new BigDecimal(milis).divide(new BigDecimal(DateUtils.MILLIS_PER_SECOND), BigDecimal.ROUND_HALF_UP); log.info("Method Invocation : "+methodinoInvocation.getThis().getClass().getName()+" : " +methodinoInvocation.getMethod().getName()+" /n Total Time of Execution : "+seconds+" Seconds "+milis+" Milis"); return methodResult; } }


Reply With Quote