Spring Framework ReloadableResourceBundleMessageSource - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Spring Framework ReloadableResourceBundleMessageSource class.

This code example shows how to use the following methods:setBasename, setDefaultEncoding, setUseCodeAsDefaultMessage
    private ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
    private LocalizedFieldNames localizedFieldNames = new LocalizedFieldNames();
 
    @Before 
    public void before() throws Exception {
        messageSource.setUseCodeAsDefaultMessage(true);
        messageSource.setBasename("classpath:/i18n/messages");
        messageSource.setDefaultEncoding("UTF-8");
        localizedFieldNames.setMessageSource(messageSource);
    } 
 
    @Test
    public void backAndForth() { 
        LocalizedFieldNames.Lookup lookup = localizedFieldNames.createLookup(Arrays.asList("dc.title"));
        final Locale english = new Locale("en");
        String title = lookup.toLocalizedName("dc_title", english);
        Assert.assertEquals("Title", title);
        String fieldName = lookup.toFieldName(title, english);
        Assert.assertEquals("dc_title", fieldName);
    } 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setBasenames, setCacheSeconds, setDefaultEncoding, setFallbackToSystemLocale
        return viewResolver;
    } 
 
    @Bean 
    public MessageSource messageSource() {
        ReloadableResourceBundleMessageSource ms = new ReloadableResourceBundleMessageSource();
        ms.setDefaultEncoding("UTF-8");
        ms.setCacheSeconds(600);
        ms.setFallbackToSystemLocale(false);
        ms.setBasenames(new String[] { "/WEB-INF/i18n/labels",
                "/WEB-INF/i18n/buttons", "/WEB-INF/i18n/messages", 
                "/WEB-INF/i18n/titles" }); 
        return ms;
    } 
 
    @Bean 
    public Validator validator() {
        LocalValidatorFactoryBean factory = new LocalValidatorFactoryBean();
        factory.setValidationMessageSource(messageSource());
        return factory;
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setBasenames, setCacheSeconds, setDefaultEncoding, setUseCodeAsDefaultMessage
    } 
 
    @Bean 
    public MessageSource messageSource() {
 
        ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
        messageSource.setBasenames("classpath:messages/messages", "classpath:messages/validation");
        // if true, the key of the message will be displayed if the key is not 
        // found, instead of throwing a NoSuchMessageException 
        messageSource.setUseCodeAsDefaultMessage(true);
        messageSource.setDefaultEncoding("UTF-8");
        // # -1 : never reload, 0 always reload 
        messageSource.setCacheSeconds(0);
        return messageSource;
    } 
} 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setBasenames, setCacheSeconds, setDefaultEncoding, setUseCodeAsDefaultMessage
@ComponentScan(basePackages = {"com.captechconsulting"}) 
public class AppConfig { 
 
    @Bean 
    public MessageSource messageSource() {
        ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
        messageSource.setBasenames("classpath:i18n/messages");
        // if true, the key of the message will be displayed if the key is not 
        // found, instead of throwing a NoSuchMessageException 
        messageSource.setUseCodeAsDefaultMessage(true);
        messageSource.setDefaultEncoding("UTF-8");
        // # -1 : never reload, 0 always reload 
        messageSource.setCacheSeconds(0);
        return messageSource;
    } 
 
} 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setBasenames, setDefaultEncoding, setFallbackToSystemLocale, setUseCodeAsDefaultMessage
     * Base message source to handle internationalization<p> 
     * Order of basenames matters, the first found property is returned  
     */ 
    @Bean 
    public MessageSource messageSource() {
        ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
        messageSource.setFallbackToSystemLocale(false);
        messageSource.setUseCodeAsDefaultMessage(true);
        messageSource.setDefaultEncoding("UTF-8");
        messageSource.setBasenames( // 
                // main resources 
                "classpath:/localization/application", "classpath:/localization/messages", // 
                // pages 
                "classpath:/localization/pages/home", // 
                "classpath:/localization/pages/login", // 
                "classpath:/localization/pages/concurrentModificationResolution", // 
                // default spring security messages 
                "classpath:org/springframework/security/messages", // 
                //  our bean validation messages 
                "classpath:ValidationMessages", // 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setBasename, setCacheSeconds, setDefaultEncoding
	} 
 
	@Bean(name = "messageSource") 
	public MessageSource configureMessageSource()
	{ 
		ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
		messageSource.setBasename("classpath:messages");
		messageSource.setCacheSeconds(5);
		messageSource.setDefaultEncoding("UTF-8");
		return messageSource;
	} 
 
	@Bean 
	public SimpleMappingExceptionResolver simpleMappingExceptionResolver()
	{ 
		SimpleMappingExceptionResolver b = new SimpleMappingExceptionResolver();
 
		Properties mappings = new Properties();
		mappings.put("org.springframework.dao.DataAccessException", "error");
		b.setExceptionMappings(mappings);
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setBasename
This code example shows how to use the following methods:setBasename, setCacheSeconds, setDefaultEncoding
	} 
 
	@Bean(name = "messageSource") 
	public MessageSource configureMessageSource()
	{ 
		ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
		messageSource.setBasename("classpath:messages");
		messageSource.setCacheSeconds(5);
		messageSource.setDefaultEncoding("UTF-8");
		return messageSource;
	} 
 
	@Bean 
	public SimpleMappingExceptionResolver simpleMappingExceptionResolver()
	{ 
		SimpleMappingExceptionResolver b = new SimpleMappingExceptionResolver();
 
		Properties mappings = new Properties();
		mappings.put("org.springframework.dao.DataAccessException", "error");
		b.setExceptionMappings(mappings);
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setBasenames, setCacheSeconds, setFallbackToSystemLocale
		return resolver;
	} 
 
	@Bean 
	public MessageSource messageSource() {
		ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
		messageSource.setFallbackToSystemLocale(false);
		messageSource.setCacheSeconds(10);
		messageSource.setBasenames(new String[] {
				"classpath:documentr_messages", "classpath:ValidationMessages" //$NON-NLS-1$ //$NON-NLS-2$ 
		}); 
		return messageSource;
	} 
 
	@Override 
	public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
		configurer.enable();
	} 
 
	@Bean 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setBasename, setCacheSeconds, setDefaultEncoding
	} 
 
	@Bean(name = "messageSource") 
	public MessageSource configureMessageSource()
	{ 
		ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
		messageSource.setBasename("classpath:messages");
		messageSource.setCacheSeconds(5);
		messageSource.setDefaultEncoding("UTF-8");
		return messageSource;
	} 
 
	@Bean 
	public SimpleMappingExceptionResolver simpleMappingExceptionResolver()
	{ 
		SimpleMappingExceptionResolver b = new SimpleMappingExceptionResolver();
 
		Properties mappings = new Properties();
		mappings.put("org.springframework.web.servlet.PageNotFound", "p404");
		mappings.put("org.springframework.dao.DataAccessException", "dataAccessFailure");
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
See Code Examples for Spring Framework ReloadableResourceBundleMessageSource Methods: