-
Notifications
You must be signed in to change notification settings - Fork 40.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow common messages to be specified for message sources #42472
Allow common messages to be specified for message sources #42472
Conversation
Extend the configuration schema to support the specification of common messages, when defining a messageSource bean
Hello all, I see this PR has been "partially" reviewed. In concept, does this pass muster, and can it be included in the coming RC? Is the idea sound here? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @mmoayyed. I've left some comments for your consideration.
/** | ||
* Comma-separated list of locale-independent common messages. | ||
*/ | ||
private String commonMessages; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we might be better off using a List<Resource>
here, that way the Binder
can take care of creating the resource instances.
|
||
try { | ||
if (StringUtils.hasText(properties.getCommonMessages())) { | ||
PropertiesFactoryBean propertiesFactory = new PropertiesFactoryBean(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might be better off using PropertiesLoaderUtils.fillProperties
here rather than PropertiesFactoryBean
. Using a FactoryBean
isn't ideal since we need to call afterPropertiesSet
etc.
.toList(); | ||
propertiesFactory.setLocations(commonResources.toArray(Resource[]::new)); | ||
propertiesFactory.setSingleton(true); | ||
propertiesFactory.setIgnoreResourceNotFound(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should fail hard if the resource is not found.
# Conflicts: # spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/context/MessageSourceProperties.java
Thank you very much @philwebb . Updated PR based on your comments and resolved conflicts with upstream. Please resume. |
Side note: I think it would be good to disable the Gradle configuration cache for the project explicitly (in case someone has it globally enabled). otherwise things like this show up:
...which can be bypassed with an explicit |
Extend message source configuration properties and auto-configuration to support common messages. See gh-42472
Thanks very much @mmoayyed, this has been merged to |
This change extends the configuration schema to support the specification of common messages, when defining a
messageSource
bean. Common messages are described here:Still in the process of testing this, and figured it would be good to post this early to get feedback.
Thank you!