-
Notifications
You must be signed in to change notification settings - Fork 38.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
<replaced-method />
unnecessarily requires explicit arg-type
since 6.0
#31826
Comments
<replaced-method />
not working properly in Spring 6
Further tested with Updated but still not working 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">
<arg-type match="java.lang.Object[]" />
</replaced-method>
</bean>
<bean id="doSomethingMethodReplacer"
class="test.spring.DoSomethingMethodReplacer" />
</beans> While adding Workaround working 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">
<arg-type match="java.lang.Object" />
</replaced-method>
</bean>
<bean id="doSomethingMethodReplacer"
class="test.spring.DoSomethingMethodReplacer" />
</beans> |
Hi @sammyhk, Thanks for raising the issue. I've confirmed it behaves the way you've explained with Spring Framework 6.0.x using the following standalone test class that I based on your example. package demo;
import java.lang.reflect.Method;
import java.util.Arrays;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.support.MethodReplacer;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.Resource;
import static org.assertj.core.api.Assertions.assertThat;
class ReplacedMethodTests {
@Test
void test() {
String xmlConfig = """
<?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="demo.ReplacedMethodTests.TestReplaceMethodBean">
<replaced-method name="doSomething" replacer="doSomethingMethodReplacer">
<!--
<arg-type match="java.lang.Object" />
-->
</replaced-method>
</bean>
<bean id="doSomethingMethodReplacer"
class="demo.ReplacedMethodTests.DoSomethingMethodReplacer" />
</beans>
""";
Resource xmlResource = new ByteArrayResource(xmlConfig.getBytes());
try (GenericApplicationContext context = new GenericApplicationContext()) {
new XmlBeanDefinitionReader(context).loadBeanDefinitions(xmlResource);
context.refresh();
TestReplaceMethodBean testBean = context.getBean(TestReplaceMethodBean.class);
assertThat(testBean.doSomething("value1", "value2")).isEqualTo("[value1, value2]");
}
}
interface TestReplaceMethodBean {
String doSomething(Object... parameters);
}
static class DoSomethingMethodReplacer implements MethodReplacer {
@Override
public Object reimplement(Object obj, Method method, Object[] args) {
return Arrays.toString((Object[]) args[0]);
}
}
} I'll investigate whether this is a regression and report back here. |
I have confirmed that the above test class passes on So this is indeed a regression, and we are investigating the issue. |
<replaced-method />
not working properly in Spring 6<replaced-method />
unnecessarily requires explicit arg-type
since 6.0.x
<replaced-method />
unnecessarily requires explicit arg-type
since 6.0.x<replaced-method />
unnecessarily requires explicit arg-type
since 6.0
Yes, that was a very good tip. Thanks! 👍 After several rounds of debugging, I determined that That's why I believe that this is a regression that was introduced in commit b31a158. I have a local prototype for a fix, so hopefully we'll be able to address this in time for tomorrow's 6.0.x and 6.1.x releases. |
This has been fixed and backported for inclusion in 6.1.2 to 6.0.15, respectively. |
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
TestReplaceMethodBean.java
DoSomethingMethodReplacer.java
TestReplacedMethod.java
It is expected to print
[value1, value2]
when run TestReplacedMethod but gotAbstractMethodError
:The text was updated successfully, but these errors were encountered: