jocom
jocom

Reputation: 69

Why I have to configure bean ResourceBundleMessageSource to use MessageSource

I don't understand why I have to create bean ResourceBundleMessageSource,

public class AppConfig {

@Bean
public ResourceBundleMessageSource messageSource(){
    ResourceBundleMessageSource source = new ResourceBundleMessageSource();
    source.setBasename("i18n/messages");
    return source;
}

to use in my class MessageSource interface?

@Autowired
private MessageSource messageSource; 

Can you explain me where is the link between ResourceBundleMessageSource and MessageSource?

Please provide me information about how can I check it in Spring code.

Thanks in advance.

Upvotes: 0

Views: 147

Answers (1)

StanislavL
StanislavL

Reputation: 57381

MessageSource is an Interface so it's spring way to use more common contract rather than implementation.

ResourceBundleMessageSource is an implementation of the MessageSource interface.

MessageSource is wider and can include other message sources not only the ResourceBundleMessageSource

Thus you add your own message source but use another one which may include aggregated message sources as well.

You can set a breakpoint and check what is real class assigned to the

private MessageSource messageSource

it's not necessary your ResourceBundleMessageSource

Upvotes: 1

Related Questions