Deprecated: implode(): Passing glue string after array is deprecated. Swap the parameters in /home/hide-tono/tono-n-chi.com/public_html/blog/wp-content/themes/simplicity2/functions.php on line 376
Spring MVC + Spring BootでValidationMessages.propertiesのメッセージが文字化けする

Spring MVC + Spring BootでValidationMessages.propertiesのメッセージが文字化けする

スポンサーリンク

毎度おなじみ、Spring Bootの標準BeanがUTF-8じゃないから文字化けしますよって話。

@Configurationなクラスに以下を貼っとけばOK。

    @Bean(name="validator")
    public LocalValidatorFactoryBean localValidatorFactoryBean() {
        LocalValidatorFactoryBean localValidatorFactoryBean = new LocalValidatorFactoryBean();
        localValidatorFactoryBean.setValidationMessageSource(messageSource());
        return localValidatorFactoryBean;
    }

    /**
     * ValidationのメッセージをUTF-8で管理します。
     * @return
     */
    @Bean(name = "messageSource")
    public MessageSource messageSource()
    {
        ReloadableResourceBundleMessageSource bean = new ReloadableResourceBundleMessageSource();
        bean.setBasename("classpath:ValidationMessages");
        bean.setDefaultEncoding("UTF-8");
        return bean;
    }

いいかげんこういうのの解決法探すのにソース追って数時間費やすのやめたい…

スポンサーリンク







シェアする

  • このエントリーをはてなブックマークに追加

フォローする

スポンサーリンク