Im working on a project where i want to externalize message. properties file. So that operation team can change according to the requirement.
For that i wrote a configuration class like this
@Configuration
@ComponentScan(basePackages = {"lk.ideahub.symphony.modules", "lk.ideahub.symphony.product"})
@PropertySources(value = {@PropertySource(value = {"classpath:messages.properties"})})
public class MessageConfig {
private static final Logger log = LoggerFactory.getLogger(MessageConfig.class);
@Bean
public MessageSource messageSource() {
log.info("Message properties loading into the project");
ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
messageSource.setBasename("classpath:messages");
messageSource.setCacheSeconds(10);
messageSource.setDefaultEncoding("UTF-8");
return messageSource;
}
}
In message properties
axipay.failure.account.already.exist=Sorry, the biller account number is already added.
In my class
public Payee myPayees{
//Asking the property into a variable
private static final String PAYEE_ACCOUNT_ALREADY_EXIST = "axipay.failure.account.already.exist";
@Autowired
Environment environment;
public void myMethod(){
String message = getEnvironment().getProperty(PAYEE_ACCOUNT_ALREADY_EXIST);
}
}