• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

CGLib error in "Before Advice" case

 
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have two class ---
1>App.class

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class App
{
public static void main(String[] args)
{
ApplicationContext appContext =
new ClassPathXmlApplicationContext(new String[]{"Spring-Customer.xml"});
CustomerService cust =
(CustomerService)appContext.getBean("customerServiceProxy");
System.out.println("****************************");
cust.printName();
System.out.println("*****************************");
cust.printURL();
System.out.println("*****************************");
try{
cust.printThrowException();
}catch(Exception e){
}
}
}



2>CustomerService.class
-----Nomal POJO class
3>Spring-Customer.xml

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="customerService" class="CustomerService" >
<property name="name" value="Yong Mook Kim" />
<property name="url" value="http://www.mkyong.com" />
</bean>
<bean id="hijackBeforeMethodBean" class="HijackBeforeMethod" />
<bean id="customerServiceProxy"
class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="target" ref="customerService" />
<property name="interceptorNames">
<list>
<value>hijackBeforeMethodBean</value>
</list>
</property>
</bean>
</beans>



when I run App.class it gave error in which it is mentioned ---

Caused by: org.springframework.aop.framework.AopConfigException: Cannot proxy ta
rget class because CGLIB2 is not available. Add CGLIB to the class path or speci
fy proxy interfaces.



I found two jar files cglib-2.2.2.jar and cglib2.jar and I have set these to classpath(first set cglib2.jar but shows some class is not getting so I add another one ).Now It is giving error like this ---

D:\BroadHop\Docs\springinaction prog\aop>java App
May 26, 2011 3:03:44 PM org.springframework.context.support.AbstractApplicationC
ontext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationCont
ext@19c26f5: startup date [Thu May 26 15:03:44 IST 2011]; root of context hierar
chy
May 26, 2011 3:03:44 PM org.springframework.beans.factory.xml.XmlBeanDefinitionR
eader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [Spring-Customer.xml
]
May 26, 2011 3:03:44 PM org.springframework.beans.factory.support.DefaultListabl
eBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.
DefaultListableBeanFactory@10655dd: defining beans [customerService,hijackBefore
MethodBean,customerServiceProxy]; root of factory hierarchy
Exception in thread "main" org.springframework.beans.factory.BeanCreationExcepti
on: Error creating bean with name 'customerServiceProxy': FactoryBean threw exce
ption on object creation; nested exception is java.lang.NoSuchMethodError: org.o
bjectweb.asm.ClassWriter.<init>(I)V
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.
doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:149)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.
getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:102)
at org.springframework.beans.factory.support.AbstractBeanFactory.getObje
ctForBeanInstance(AbstractBeanFactory.java:1429)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBe
an(AbstractBeanFactory.java:245)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean
(AbstractBeanFactory.java:190)
at org.springframework.context.support.AbstractApplicationContext.getBea
n(AbstractApplicationContext.java:1075)
at App.main(App.java:15)
Caused by: java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(I)V

at net.sf.cglib.core.DebuggingClassWriter.<init>(DebuggingClassWriter.ja
va:47)
at net.sf.cglib.core.DefaultGeneratorStrategy.getClassWriter(DefaultGene
ratorStrategy.java:30)
at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorS
trategy.java:24)
at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerato
r.java:216)
at net.sf.cglib.core.KeyFactory$Generator.create(KeyFactory.java:144)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:116)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:108)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:104)
at net.sf.cglib.proxy.Enhancer.<clinit>(Enhancer.java:69)
at org.springframework.aop.framework.Cglib2AopProxy.createEnhancer(Cglib
2AopProxy.java:228)
at org.springframework.aop.framework.Cglib2AopProxy.getProxy(Cglib2AopPr
oxy.java:170)
at org.springframework.aop.framework.ProxyFactoryBean.getProxy(ProxyFact
oryBean.java:362)
at org.springframework.aop.framework.ProxyFactoryBean.getSingletonInstan
ce(ProxyFactoryBean.java:316)
at org.springframework.aop.framework.ProxyFactoryBean.getObject(ProxyFac
toryBean.java:242)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.
doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:142)
... 6 more



please suggest what to do


 
Abhra Kar
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry I forget to add
I have another Class HijackBeforeMethod.java

import java.lang.reflect.Method;
import org.springframework.aop.MethodBeforeAdvice;

public class HijackBeforeMethod implements MethodBeforeAdvice
{
@Override
public void before(Method method, Object[] args, Object target)
throws Throwable {
System.out.println("HijackBeforeMethod : Before method hijacked!");
}
}

 
Abhra Kar
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what actual jar file I should set in classpath?
I have added these jars in classpath--

set classpath=.;D:\sjars\

org.springframework.aop_3.0.5.RELEASE.jar

;D:\sjars\

org.springframework.asm_3.0.5.RELEASE.jar

;D:\sjars\

org.springframework.aspects_3.0.5.RELEASE.jar

;D:\sjars\

org.springframework.beans_3.0.5.RELEASE.jar

;D:\sjars\

org.springframework.context.support_3.0.5.RELEASE.jar

;D:\sjars\

org.springframework.context_3.0.5.RELEASE.jar

;D:\sjars\

org.springframework.core_3.0.5.RELEASE.jar

;D:\sjars\

org.springframework.expression_3.0.5.RELEASE.jar

;D:\sjars\

org.springframework.instrument.tomcat_3.0.5.RELEASE.jar

;D:\sjars\

org.springframework.instrument_3.0.5.RELEASE.jar

;D:\sjars\

org.springframework.jdbc_3.0.5.RELEASE.jar

;D:\sjars\

org.springframework.jms_3.0.5.RELEASE.jar

;D:\sjars\

org.springframework.orm_3.0.5.RELEASE.jar

;D:\sjars\

org.springframework.oxm_3.0.5.RELEASE.jar

;D:\sjars\

org.springframework.test_3.0.5.RELEASE.jar

;D:\sjars\

org.springframework.transaction_3.0.5.RELEASE.jar

;D:\sjars\

org.springframework.web.portlet_3.0.5.RELEASE.jar

;D:\sjars\

org.springframework.web.servlet_3.0.5.RELEASE.jar

;D:\sjars\

org.springframework.web.struts_3.0.5.RELEASE.jar

;D:\sjars\

org.springframework.web_3.0.5.RELEASE.jar

;D:\sjars\

commons-logging-api-1.1.1.jar

;D:\sjars\

aopalliance-1.0.jar

;D:\sjars\

cglib-2.2.2.jar

;D:\sjars\

cglib2.jar

 
Ranch Hand
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to have asm.jar in your classpath..
 
That feels good. Thanks. Here's a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic