0

I am not able to read application.properties file but I am able to read messages_en_IN.properties file.

I am using maven project and both of my properties files are in resource folder

Below is my configuration

public class WebAppConfig extends WebMvcConfigurerAdapter {

// resource bundle configuration
@Bean
public ReloadableResourceBundleMessageSource messageSource(){
    ReloadableResourceBundleMessageSource messageSource=new ReloadableResourceBundleMessageSource();
    String[] resources= {"classpath:messages"};
    messageSource.setBasenames(resources);
    return messageSource;
}

@Bean
public LocaleResolver localeResolver() {
    final CookieLocaleResolver ret = new CookieLocaleResolver();
    ret.setDefaultLocale(new Locale("en_IN"));
    return ret;
}

@Bean 
public LocaleChangeInterceptor localeChangeInterceptor(){
    LocaleChangeInterceptor localeChangeInterceptor=new LocaleChangeInterceptor();
    localeChangeInterceptor.setParamName("language");
    return localeChangeInterceptor;
}

// properties file configuration
@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
    PropertySourcesPlaceholderConfigurer propertySources = new PropertySourcesPlaceholderConfigurer();
    org.springframework.core.io.Resource[] resources = new ClassPathResource[ ] { new ClassPathResource( "application.properties" ) };
    propertySources.setLocations((org.springframework.core.io.Resource[]) resources);
    return propertySources;
}
}

JSP: to read properties

spring:message code="label.maxlength"

exception:

No message found under code 'label.maxlength' for locale 'en_in'

label.maxlength is in application.properties but if I try to read something from messages_en_IN.properties it is working fine. Why it is not reading from application.properties

Thanks

pise
  • 849
  • 6
  • 24
  • 51
  • can you try editing your code as below :// properties file configuration @Bean public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() { PropertySourcesPlaceholderConfigurer propertySources = new PropertySourcesPlaceholderConfigurer(); org.springframework.core.io.Resource[] resources = new ClassPathResource[ ] { new ClassPathResource( "application.properties","messages_en_IN.properties") }; propertySources.setLocations((org.springframework.core.io.Resource[]) resources); return propertySources; } – Arpit Aggarwal Apr 24 '15 at 10:41
  • @Arpit You added messages_en_IN.properties in my code but there is no issue in reading bundle resource properties file. So is there any need in adding message_en_IN.properties file? – pise Apr 24 '15 at 11:07
  • No, I understand it differently. Your code is well written. Ideally it should work, moreover you have a refernce from : http://www.baeldung.com/2012/02/06/properties-with-spring/ – Arpit Aggarwal Apr 24 '15 at 12:08
  • @Arpit to get property value on jsp do I need to use ``. Please see [this](http://stackoverflow.com/questions/15111260/how-to-show-values-from-property-file-in-jsp-in-a-spring-mvc-app). Will implement this and revert back. – pise Apr 24 '15 at 13:27
  • That's a classic way. Please go ahead! – Arpit Aggarwal Apr 24 '15 at 13:36

0 Answers0