Allow flexible constructor arguments in factory implementations
Update `SpringFactoriesLoader` so that factory implementation classes can have a constructor with arguments that are resolved dynamically. Arguments are resolved using a `ArgumentResolver` interface that is passed to the `loadFactories` method. This strategy interface is intentionally simple and only allows resolution based on the argument type. A number of convenience methods are provided to allow resolvers to be built. For example: ArgumentResolver.of(String.class, "tests") .and(Integer.class, 123); Factory implementation classes must have a non-ambiguous constructor in order to be instantiated. The `SpringFactoriesLoader` uses the same algorithm as `BeanUtils.getResolvableConstructor`. See gh-28057 Co-authored-by: Madhura Bhave <bhavem@vmware.com> Co-authored-by: Andy Wilkinson <wilkinsona@vmware.com>
This commit is contained in:
committed by
Stephane Nicoll
parent
ae1956cac7
commit
0b716c4f90
@@ -0,0 +1,2 @@
|
||||
org.springframework.core.io.support.DummyFactory=\
|
||||
org.springframework.core.io.support.ConstructorArgsDummyFactory
|
||||
@@ -0,0 +1,2 @@
|
||||
org.springframework.core.io.support.DummyFactory=\
|
||||
org.springframework.core.io.support.MultipleConstructorArgsDummyFactory
|
||||
Reference in New Issue
Block a user