MessageSourceAware Interface in Spring

  • In Spring, the bean that implements the MessageSourceAware Interface gets notified about the application context in which it is. running.
  • E.g. If the object is running in a US locale application, then it is notified and configured for the US locale.
  • setMessageSource() method must have to be implemented for automatic injection of reference.

MessageSourceAware Java Bean Format

The java bean with message source aware is created as below:

Java




//Java code for Bean Specific Logic
public class BeanName implements MessageSourceAware
{
    private MessageSource messageSource;
  
    public void setMessageSource(MessageSource messageSource) {
        this.messageSource = messageSource;
    }
}


In the above example the bean has implemented MessageSourceAware Interface and implemeted setMessageSource method that sets message source.

Spring MessageSourceAware Java Bean Example

MessageSourceAware in Spring can be used to implement internationalization in Java. If different locales have to be implemented in a web application, then configuring different resources can be performed using MessageSourceAware. So, let’s see how we can configure Java Bean that implements MessageSourceAware.

Prerequisite Topic

  • Spring: Spring is a Java framework that helps in the development of production-grade, microservice-based web applications and Apis.
  • Spring Bean: Spring Bean is a reusable class that helps in creating objects and performing various tasks in web applications.

Similar Reads

MessageSourceAware Interface in Spring

In Spring, the bean that implements the MessageSourceAware Interface gets notified about the application context in which it is. running. E.g. If the object is running in a US locale application, then it is notified and configured for the US locale. setMessageSource() method must have to be implemented for automatic injection of reference....

Spring MessageSourceAware Java Bean Example

...

Contact Us