Skip to content

Commit

Permalink
ConstructorResolver.resolveConstructorArguments() return value issue
Browse files Browse the repository at this point in the history
  • Loading branch information
why committed Jun 18, 2020
1 parent 8128abc commit 54776ec
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 0 deletions.
@@ -0,0 +1,23 @@
package cases.constructorArgWithIndex;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
* https://mp.weixin.qq.com/s/bIpnXFTXuNq5WzBlRdVVNQ
* <p>文章修复了一个代码的问题,当时我测试的时候并没有发现修改之前会有异常,可能是修复之后使代码更加合理吧。
* <p>文章修复的问题 5.2.7 发布了,issues: https://github.com/spring-projects/spring-framework/issues/25130
*
* @author wanghuanyu
*/
public class ConstructorArgWithIndexDemo {

public static void main(String[] args) {
ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
"classpath:META-INF/cases/constructorArgWithIndex.xml");

DmzService service = applicationContext.getBean("dmzService", DmzService.class);
System.out.println(service);

}
}
@@ -0,0 +1,19 @@
package cases.constructorArgWithIndex;

/**
* @author wanghuanyu
*/
public class DmzService {

private String name;
private OrderService orderService;

public DmzService(OrderService orderService, String name) {
this.orderService = orderService;
this.name = name;
}

public DmzService(String name) {
this.name = name;
}
}
@@ -0,0 +1,30 @@
package cases.constructorArgWithIndex;

import java.util.Date;

/**
* @author wanghuanyu
*/
public class FactoryObject {

public DmzService getDmz(String name, int age, Date birthDay, OrderService orderService) {
return new DmzService(orderService, name);
}

public DmzService getDmz(String name, Date birthday) {
return new DmzService(name);
}

// public DmzService getDmz(String name, OrderService orderService) {
// return new DmzService(name);
// }

public DmzService getDmz(String name, int age) {
return new DmzService(name);
}

public DmzService getDmz(String name) {
return new DmzService(name);
}

}
@@ -0,0 +1,8 @@
package cases.constructorArgWithIndex;

/**
* @author wanghuanyu
*/
public class OrderService {

}
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd"
default-autowire="constructor">


<bean id="factoryObject" class="cases.constructorArgWithIndex.FactoryObject"/>

<bean class="cases.constructorArgWithIndex.OrderService" id="orderService"/>

<bean id="dmzService" factory-bean="factoryObject" factory-method="getDmz">
<constructor-arg index="0" value="mm"/>
</bean>

</beans>

0 comments on commit 54776ec

Please sign in to comment.