spring-framework icon indicating copy to clipboard operation
spring-framework copied to clipboard

Make ResourceBundleMessageSource support more file formats [SPR-14419]

Open spring-projects-issues opened this issue 8 years ago • 20 comments

Loïc Dreux opened SPR-14419 and commented

ResourceBundleMessageSource could store and load Properties with a custom implementation of the PropertiesPersister like YamlPropertiesPersister.java but the extensions ".properties" and ".xml" are hard coded in Java Source.

A good solution could be to had a property "customExtension" to support other file format like yaml.


Affects: 4.2.6

spring-projects-issues avatar Jun 29 '16 15:06 spring-projects-issues

Bulk closing outdated, unresolved issues. Please, reopen if still relevant.

spring-projects-issues avatar Jan 12 '19 00:01 spring-projects-issues

I would say it's relevant!

62mkv avatar Mar 15 '19 14:03 62mkv

I think this is relevant too. All my application is YAML configured (properties, liquibase..) excepted messages. It's really frustrating. Without this support we must use two different markup language to maintain our projects.

pierrickrouxel avatar Jul 19 '19 10:07 pierrickrouxel

Is it possible to reopen an issue?

Gorynych avatar Dec 29 '19 14:12 Gorynych

i think it is relevant too

MysteryMS avatar Sep 02 '20 18:09 MysteryMS

It's relevant!

tonyfarney avatar Oct 03 '20 19:10 tonyfarney

any updates on this?

ghahramani avatar Nov 29 '20 00:11 ghahramani

Really waiting for it!!! It's relevant!

cristianchies avatar Nov 30 '20 21:11 cristianchies

At least tell us when will this be resolved.

ashutosh049 avatar Jan 08 '21 02:01 ashutosh049

This issue still relevant

m-a-g-i-c avatar Mar 25 '21 16:03 m-a-g-i-c

I am here too. Seems relevant to me

ghost avatar Apr 11 '21 05:04 ghost

Nice issue

wesleyody avatar Jul 06 '21 16:07 wesleyody

I really like this issue! 💕

renanfranca avatar Jul 20 '21 00:07 renanfranca

look forward

5452 avatar Sep 14 '21 08:09 5452

I would really appreciate this feature!

christian-kocke avatar Feb 21 '22 13:02 christian-kocke

@christian-kocke I found a repo with a work around of this issue, hope it helps. https://github.com/akkinoc/yaml-resource-bundle

smunozudp avatar Feb 27 '22 01:02 smunozudp

it is relevant for sure!

grzeg avatar Apr 22 '22 12:04 grzeg

yes, it's relevant

viviendehorta avatar May 08 '22 00:05 viviendehorta

I agree, this is a very relevant feature

luismarques99 avatar Sep 19 '22 21:09 luismarques99

Yep. Lots of us need this. Anything that's hard-coded is really bad code, so it's high time it was refactored anyways. Externalize it and use polymorphism to support Yaml!

jmussman avatar Oct 28 '22 17:10 jmussman

And here I am again too checking for any updates. Still find it relevant

slimane-deb avatar Nov 30 '22 10:11 slimane-deb

It's super relevant!

javadev-jef avatar Feb 20 '23 15:02 javadev-jef

Thanks for your input everyone, we will be addressing this feature request in 6.1.

poutsma avatar Feb 22 '23 12:02 poutsma

It is relevant for me as well :)

malikalamgirian avatar Feb 22 '23 14:02 malikalamgirian

Thanks for your input everyone, we will be addressing this feature request in 6.1.

YES! it took almost 7 years... but we got it 🎉🎉🎉

MysteryMS avatar Feb 22 '23 14:02 MysteryMS

Thanks for your input everyone, we will be addressing this feature request in 6.1.

YES! it took almost 7 years... but we got it 🎉🎉🎉

From which version of Spring Boot is this feature available ? Any resource available with example of its usage would be nice.

Thanthu avatar Jun 23 '23 10:06 Thanthu

From which version of Spring Boot is this feature available ? Any resource available with example of its usage would be nice.

@Thanthu, this issue is still open, which means that the feature has not been released yet.

sbrannen avatar Jun 23 '23 10:06 sbrannen

Thanks everybody for your patience, this issue should be be fixed by this commit.

I was a bit confused initially by the fact that the description of the changes proposed looked irrelevant to ResourceBundleMessageSource, but I understood after digging deeper that it was a typo, and that the change was targeting ReloadableResourceBundleMessageSource which allows to set a custom PropertiesPersister and indeed had .properties and .xml extensions hard coded. The title and description of the issue have been updated accordingly.

In ReloadableResourceBundleMessageSource, it is now possible to customize the file extensions thanks to a new setFileExtensions setter, and combined with setPropertiesPersister, it is possible to implement support for custom file formats.

Since it seems to be a popular use case, I have implemented an example of YAML resource bundle support in https://github.com/sdeleuze/demo-yaml-message-source. The important bits are the YamlPropertiesLoader leveraging org.springframework.beans.factory.config.YamlMapFactoryBean and the declaration of a custom MessageSource bean here:

@Bean
public MessageSource messageSource() {
	ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
	messageSource.setBasename("classpath:messages");
	messageSource.setPropertiesPersister(new YamlPropertiesLoader());
	messageSource.setFileExtensions(List.of(".yml", ".yaml"));
	return messageSource;
}

Spring does not provide such out-of-the box YAML support yet, but hopefully that can serve as an example for the community for how to leverage this feature, and will allow the Spring team to observe how the community leverages those capabilities, which implementations get traction, etc.

sdeleuze avatar Aug 03 '23 12:08 sdeleuze

this issue has been closed. does that mean Spring framework out of the box finally support yaml format for message source?

hannah23280 avatar Sep 04 '23 00:09 hannah23280

if out the box is supported, does spring boot able to autoconfigure to support both yaml and properties, instead of developer having to write codes to configure them.

hannah23280 avatar Sep 04 '23 00:09 hannah23280