I'm trying to replace a calcInt method in Bank class with a new method
in a new Class NewCalcInt.java. But I'm not able to do that. Help me to
solve this. I have added all the JAR's along with cglib-nodep-2.1.3 jar.
This is the following code Bank.java
package beans;
public class Bank {
public void deposit() {
System.out.println("Deposit Method in Bank");
}
public void withdraw() {
System.out.println("Withdraw Method in Bank");
}
public void calcInt() {
System.out.println("CalcInt Method in Bank");
}
}
The following program is NewCalcInt.java
NewCalcInt.java
package beans;
import java.lang.reflect.Method;
import org.springframework.beans.factory.support.MethodReplacer;
public class NewCalcInt implements MethodReplacer {
public Object reimplement(Object o, Method m, Object[] arg2) throws
Throwable {
System.out.println("NewCalcInt class new CalInt imp");
return o;
}
}
The following code is spring.xml spring.xml
<?xml version="1.0" encoding="UTF-8"?>
<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-3.0.xsd" >
<bean id="b" class="beans.Bank">
<replaced-method name="calcInt" replacer="nc"></replaced-method>
</bean>
<bean id="nc" class="beans.NewCalcInt"></bean>
</beans>
The following code is ClientApp.java ClientApp.java
package beans;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class ClientApp {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
Bank b = (Bank) context.getBean("b");
b.deposit();
b.withdraw();
b.deposit();
}
}
I have already add the JARs