kolorobot / spring-mvc-quickstart-archetype

The project is a Maven archetype for Spring MVC web application.
http://blog.codeleak.pl
1.05k stars 478 forks source link

Default encoding for messageSource bean #124

Closed John-Chan closed 7 years ago

John-Chan commented 7 years ago

Test code

@Configuration
class ResourceConfig {

    private static final String MESSAGE_SOURCE = "/i18n/messages";
    @Bean(name = "messageSource")
    public MessageSource messageSource() {
        ReloadableResourceBundleMessageSource messageSource = new    ReloadableResourceBundleMessageSource();
        messageSource.setBasename(MESSAGE_SOURCE);
        //messageSource.setDefaultEncoding("UTF-8");
        messageSource.setCacheSeconds(5);
        return messageSource;
    }
}

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {ResourceConfig.class} )
public class TestMessageSource {

    @Resource(name = "messageSource")
    private MessageSource messageSource;

    @Test
    public void testGetMessageCN(){

        final String MSG_KEY = "hello.message";
        String[] para={"john","www.example.com"};
        String msgCN= messageSource.getMessage(MSG_KEY, para, new Locale("zh", "CN"));
    }
}

The encoding of msgCN is not correct unless call messageSource.setDefaultEncoding("UTF-8");

kolorobot commented 7 years ago

Fixed. Released in 1.0.1. Thanks!