Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ConstructorResolver.resolveConstructorArguments() return value issue
- Loading branch information
why
committed
Jun 18, 2020
1 parent
8128abc
commit 54776ec
Showing
5 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
...ng-framework/src/main/java/cases/constructorArgWithIndex/ConstructorArgWithIndexDemo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
|
||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
spring-framework/src/main/java/cases/constructorArgWithIndex/DmzService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
spring-framework/src/main/java/cases/constructorArgWithIndex/FactoryObject.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
spring-framework/src/main/java/cases/constructorArgWithIndex/OrderService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package cases.constructorArgWithIndex; | ||
|
||
/** | ||
* @author wanghuanyu | ||
*/ | ||
public class OrderService { | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
spring-framework/src/main/resources/META-INF/cases/constructorArgWithIndex.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |