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){
}
}
}
<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>
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.
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
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!");
}
}
set classpath=.;D:\sjars\
;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
cglib2.jar
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
|