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
Add support for ReloadableResourceBundleMessageSource #13377
Add support for ReloadableResourceBundleMessageSource #13377
Conversation
This commit adds support for `ReloadableResourceBundleMessageSource`, by adding a `spring.messages.reloadable` configuration property, which can be set to `true` to force the `messageSource` bean to be an instance of that class.
9f15868
to
302f3c9
Compare
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've flagged this one for team attention and it hasn't been triaged yet so need to act on it for now.
I've added a few comments.
@@ -71,6 +73,12 @@ | |||
*/ | |||
private boolean useCodeAsDefaultMessage = false; | |||
|
|||
/** | |||
* Whether to use a {@link ReloadableResourceBundleMessageSource} instead of the |
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.
Configuration key descriptions can't have javadoc tag (see documentation). I think we need to improve the description as high-level descriptions shouldn't contain implementation details (rather it should describe what the feature does).
@@ -220,6 +224,45 @@ public void existingMessageSourceInParentIsIgnored() { | |||
.isEqualTo("bar"))); | |||
} | |||
|
|||
@Test | |||
public void testDefaultReloadableValueMessageSource() { | |||
this.contextRunner.withPropertyValues("spring.messages.basename:test/messages") |
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.
This assertion can be added to the existing basic test
"spring.messages.reloadable:true").run((context) -> { | ||
assertThat(getDeclaredMessageSource(context)) | ||
.isInstanceOf(ReloadableResourceBundleMessageSource.class); | ||
assertThat(context.getMessage("foo", null, "Foo message", Locale.UK)) |
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.
What is the purpose of this assertion?
We discussed this a little and we're not too sure on the best way to continue. It would certainly be nice to offer an easy way to plug-in a custom There is some precedent for controlling caching with properties. For example with |
Thanks for the input. I understand that having a configuration property that "decides" which implementation to use is not ideal at all, and I wouldn't mind if I had to explicitly declare a bean for that: @Bean
public MessageSource messageSource() {
return new ReloadableResourceBundleMessageSource();
} But then, I would have to configure it myself (even One possible idea would be to configure that declared |
* pr/13377: Polish "Add ReloadableResourceBundleMessageSource support" Add ReloadableResourceBundleMessageSource support
Should dev tools set |
@candrews probably, yes. Can you please create a separate issue? |
With some regret, we've decided to revert this change. With hindsight, we don't think that the approach taken here is quite right. In particular, setting |
I've opened #15007. |
I understand, I honestly didn't expect this to be merged, because we were still discussing if my approach was the best one. I was already convinced it wasn't, and your point regarding files placement is a very good point against this approach. |
BTW it seems like it wasn't removed from the changelogs:
P.S. Yes, I know it's quite old and 2.1 is EOL. |
@php-coder this change was reverted after RC1 was released so the current changelog is accurate. |
This PR adds support for
ReloadableResourceBundleMessageSource
, by adding aspring.messages.reloadable
configuration property, which can be set totrue
to force themessageSource
bean to be an instance of that class.I'm currently working on a legacy Spring project that is progressively being migrated into Spring Boot, and we use a
ReloadableResourceBundleMessageSource
there, and we would like to replace it with theMessageSourceAutoConfiguration
.I'm well aware of #3039, and that:
However, Devtools is not an option in this project, and even if it was, reloading all the application takes much more time than the
ReloadableResourceBundleMessageSource
takes to refresh.I think that changes to enable
ReloadableResourceBundleMessageSource
support are minimal, and the new introduced configuration,spring.messages.reloadable
is set tofalse
by default, so it's backaward compatible.