This repository was archived by the owner on Feb 23, 2023. It is now read-only.
Fix factory name with spaces in "spring.factories"#1421
Merged
sdeleuze merged 1 commit intospring-attic:mainfrom Jan 4, 2022
Merged
Fix factory name with spaces in "spring.factories"#1421sdeleuze merged 1 commit intospring-attic:mainfrom
sdeleuze merged 1 commit intospring-attic:mainfrom
Conversation
When an entry value of `spring.factories` starts with space, `SpringFactoriesContributor` fails to resolve the target class, which in turn skips the creation of the factory bean. In Spring Framework, it applies `trim()` to each comma-delimited entry value. This commit adds `trim()` to match the behavior and make correctly resolve the target factory class. Signed-off-by: Tadaya Tsuyukubo <tadaya@ttddyy.net>
This file contains hidden or 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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In
spring.factories, when there is a space after comma delimiter, it fails to resolve the class and does not create the correspondingSpringFactory.The following
spring.factoriesonly pick upFactoryFoobecause there is a space after the comma.com.example.MyFactory =\ com.example.FactoryFoo, com.example.FactoryBarcom.example.MyFactory =\ com.example.FactoryFoo, \ com.example.FactoryBarThis is because when this entry is loaded and split to an array, it is interpreted as
["com.example.FactoryFoo", " com.example.FactoryBar"]. The second entry contains a space in front. So that when it createsSpringFactoryinSpringFactoriesContributorit cannot resolve the target class and it is skipped.In Spring Framework, it applies
trim()to each entry value.https://github.com/spring-projects/spring-framework/blob/8dd385b440cb2e432ce7151be08d313982d3b00c/spring-core/src/main/java/org/springframework/core/io/support/SpringFactoriesLoader.java#L153
This PR adds
trim()while processing thespring.factoriesinSpringFactoriesContributor; so that it properly recognizes the entry with spaces.