Skip to content
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
merged 1 commit into from
Jan 4, 2022

Conversation

ttddyy
Copy link
Contributor

@ttddyy ttddyy commented Jan 4, 2022

In spring.factories, when there is a space after comma delimiter, it fails to resolve the class and does not create the corresponding SpringFactory.

The following spring.factories only pick up FactoryFoo because there is a space after the comma.

com.example.MyFactory =\
com.example.FactoryFoo, com.example.FactoryBar
com.example.MyFactory =\
com.example.FactoryFoo, \
com.example.FactoryBar

This 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 creates SpringFactory in SpringFactoriesContributor it 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 the spring.factories in SpringFactoriesContributor; so that it properly recognizes the entry with spaces.

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>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jan 4, 2022
@sdeleuze sdeleuze added this to the 0.11.2 milestone Jan 4, 2022
@sdeleuze sdeleuze added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jan 4, 2022
@sdeleuze sdeleuze merged commit 79b9851 into spring-attic:main Jan 4, 2022
@ttddyy ttddyy deleted the trim-factory-entry branch January 4, 2022 21:32
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: enhancement A general enhancement
Development

Successfully merging this pull request may close these issues.

3 participants