Closed
Description
Affects: 6.1.1
We are migrating from Spring 5.3.x to 6.1.1 and found seems not working in the XML definition. Consider the following example:
applicationContext.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.xsd">
<bean id="testReplaceMethodBean" class="test.spring.TestReplaceMethodBean">
<replaced-method name="doSomething"
replacer="doSomethingMethodReplacer" />
</bean>
<bean id="doSomethingMethodReplacer"
class="test.spring.DoSomethingMethodReplacer" />
</beans>
TestReplaceMethodBean.java
package test.spring;
public interface TestReplaceMethodBean {
String doSomething(Object... parameters);
}
DoSomethingMethodReplacer.java
package test.spring;
import java.lang.reflect.Method;
import java.util.Arrays;
import org.springframework.beans.factory.support.MethodReplacer;
public class DoSomethingMethodReplacer implements MethodReplacer {
@Override
public Object reimplement(Object obj, Method method, Object[] args) throws Throwable {
return Arrays.toString((Object[]) args[0]);
}
}
TestReplacedMethod.java
package test.spring;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class TestReplacedMethod {
public static void main(String[] args) {
try (AbstractApplicationContext applicationContext = new ClassPathXmlApplicationContext(
"classpath*:path/to/applicationContext.xml")) {
TestReplaceMethodBean testBean = applicationContext.getBean(TestReplaceMethodBean.class);
// expecting to print "[value1, value2]"
System.out.println(testBean.doSomething(new Object[] { "value1", "value2" }));
}
}
}
It is expected to print [value1, value2]
when run TestReplacedMethod but got AbstractMethodError
:
Exception in thread "main" java.lang.AbstractMethodError: Receiver class test.spring.TestReplaceMethodBean$$SpringCGLIB$$0 does not define or inherit an implementation of the resolved method 'abstract java.lang.String doSomething(java.lang.Object[])' of interface test.spring.TestReplaceMethodBean.
at test.spring.TestReplacedMethod.main(TestReplacedMethod.java:12)