Filter out duplicates in SpringFactoriesLoader
Prior to this commit, SpringFactoriesLoader discovered all registered factory implementations for a given factory type even if duplicates were registered within a single META-INF/spring.factories file or in multiple such files in the classpath. This commit updates the internals of SpringFactoriesLoader so that duplicate registrations are ignored, thereby aligning with the well-known semantics for java.util.ServiceLoader in this regard. Closes gh-24985
This commit is contained in:
@@ -34,7 +34,13 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
|
||||
class SpringFactoriesLoaderTests {
|
||||
|
||||
@Test
|
||||
void loadFactoriesInCorrectOrder() {
|
||||
void loadFactoriesWithNoRegisteredImplementations() {
|
||||
List<Integer> factories = SpringFactoriesLoader.loadFactories(Integer.class, null);
|
||||
assertThat(factories).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void loadFactoriesInCorrectOrderWithDuplicateRegistrationsPresent() {
|
||||
List<DummyFactory> factories = SpringFactoriesLoader.loadFactories(DummyFactory.class, null);
|
||||
assertThat(factories).hasSize(2);
|
||||
assertThat(factories.get(0)).isInstanceOf(MyDummyFactory1.class);
|
||||
|
||||
Reference in New Issue
Block a user