java - Heroku 应用程序不显示以 UTF-8 作为默认编码的西里尔字符

标签 java spring-boot heroku locale

我正在关注this Baeldung tutorial尽管语言更改正确,但每当我尝试更改为基于西里尔文的语言(保加利亚语、俄语)时,字符只是问号。我在 Heroku 上托管我的应用程序。

我尝试在 Heroku CLI 中执行 heroku config:add LANG=en_US.UTF-8 但没有效果。

这是我的 LocaleResolverReloadableResourceBundleMessageSourceLocaleChangeInterceptor 和重写的 addInterceptors 方法的代码

    @Bean
    public LocaleResolver localeResolver() {
        SessionLocaleResolver slr = new SessionLocaleResolver();
        slr.setDefaultLocale(Locale.US);
        return slr;
    }

    @Bean
    public ReloadableResourceBundleMessageSource messageSource() {
        ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
        messageSource.setBasename("classpath:messages");
        messageSource.setDefaultEncoding("UTF-8"); 
        return messageSource;
    }

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

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(localeChangeInterceptor());
    }

我希望得到“Добре дошъл”(保加利亚语欢迎),但我只是得到???????相反。

编辑 1 添加Heroku Locale Buildpack后,当我尝试将应用程序部署到 Heroku 时,出现以下错误:

-----> Locale app detected
cat: /tmp/build_1406e9f58f41cacf3931deb52b55d687/.locales: No such file or 
directory
!     Push rejected, failed to compile Locale app.
!     Push failed

最佳答案

如果您已安装区域设置构建包,请转至 Heroku 应用的设置来删除您创建的 .locales 文件和构建包。

我通过在 application.properties 文件中应用以下设置解决了该问题:

spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
spring.http.encoding.force=true

此外,应用这些设置后的第一次构建可能会特别慢 - 如果您在 Eclipse 中构建并且习惯于在大约 1 分钟内构建 Heroku 应用程序,请注意这可能需要超过 5 分钟构建。

关于java - Heroku 应用程序不显示以 UTF-8 作为默认编码的西里尔字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56382338/

相关文章:

java - Hibernate 配置未列出 XML 中的所有实体

java - 使用 FreeMarker 从 select 返回值

python - foreman 未启动名为 myapp 的模块

python - Heroku Python 本地环境变量

javascript - 在 Heroku 上部署 Node.js 失败 : TypeError: Cannot read property 'split' of null

java - JFrame最大化时如何调整JPanel的大小?

java - 使用 Jmeter 和 Junit 进行负载测试时,setUp 和tearDown 如何工作?

java - 如何从javascript发送具有相同编码的参数?

intellij-idea - IntelliJ 15,SpringBoot devtools livereload 不起作用

java - 如何在 Spring Boot 2.0 中启用 "hystrix.stream"?