【Azure Function App】Java Function部署到Azure后出现中文显示乱码问题

问题描述

Java Function在Azure上遇见中文显示乱码问题?如何解决呢?

 

问题解答

中文字符显示为乱码,这个情况就是服务实例上设置的编码格式不是统一的UTF-8所导致的。

在查看Azure App Service/Function App的官方文档,都没有明确的说明它们使用的默认编码是什么,通过询问ChatGPT-4,也没有得到确定的答案。

但是要解决这个问题,可以设置 Function App的 Application Setting。 添加 JAVA_OPTS ,然后设置值为 -Dfile.encoding=UTF-8

注:App Service 与 Function App 一样,都是通过添加 JAVA_OPTS 参数来设置编码格式。

 

参考资料

Configure a Java app for Azure App Service -- Set default character encoding : https://learn.microsoft.com/en-us/azure/app-service/configure-language-java?pivots=platform-windows#set-default-character-encoding

Set default character encoding

In the Azure portal, under Application Settings for the web app, create a new app setting named JAVA_OPTS with value -Dfile.encoding=UTF-8.

Alternatively, you can configure the app setting using the App Service Maven plugin. Add the setting name and value tags in the plugin configuration:

<appSettings>
    <property>
        <name>JAVA_OPTS</name>
        <value>-Dfile.encoding=UTF-8</value>
    </property>
</appSettings>
 

 

posted @ 2023-07-19 20:57  路边两盏灯  阅读(53)  评论(0编辑  收藏  举报