码迷,mamicode.com
首页 > 其他好文 > 详细

NACOS MalformedInputException 无法读取中文配置问题

时间:2020-03-09 22:27:18      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:nic   osd   设置   java   fine   initial   cto   uil   nconf   

1. 问题描述

在windows平台中打包运行springboot jar包提示如下错误

  • 在idea中运行正常
org.yaml.snakeyaml.error.YAMLException: java.nio.charset.MalformedInputException: Input length = 1
        at org.yaml.snakeyaml.reader.StreamReader.update(StreamReader.java:254) ~[snakeyaml-1.19.jar!/:na]
        at org.yaml.snakeyaml.reader.StreamReader.<init>(StreamReader.java:58) ~[snakeyaml-1.19.jar!/:na]
        at org.yaml.snakeyaml.Yaml.loadAll(Yaml.java:537) ~[snakeyaml-1.19.jar!/:na]
        at org.springframework.beans.factory.config.YamlProcessor.process(YamlProcessor.java:166) ~[spring-beans-5.0.12.RELEASE.jar!/:5.0.12.RELEASE]
        at org.springframework.beans.factory.config.YamlProcessor.process(YamlProcessor.java:139) ~[spring-beans-5.0.12.RELEASE.jar!/:5.0.12.RELEASE]
        at org.springframework.beans.factory.config.YamlPropertiesFactoryBean.createProperties(YamlPropertiesFactoryBean.java:135) ~[spring-beans-5.0.12.RELEASE.jar!/:5.0.12.RELEASE]
        at org.springframework.beans.factory.config.YamlPropertiesFactoryBean.getObject(YamlPropertiesFactoryBean.java:115) ~[spring-beans-5.0.12.RELEASE.jar!/:5.0.12.RELEASE]
        at org.springframework.cloud.alibaba.nacos.client.NacosPropertySourceBuilder.loadNacosData(NacosPropertySourceBuilder.java:100) [spring-cloud-alibaba-nacos-config-0.9.0.RELEASE.jar!/:0.9.0.RELEASE]
        at org.springframework.cloud.alibaba.nacos.client.NacosPropertySourceBuilder.build(NacosPropertySourceBuilder.java:75) [spring-cloud-alibaba-nacos-config-0.9.0.RELEASE.jar!/:0.9.0.RELEASE]
        at org.springframework.cloud.alibaba.nacos.client.NacosPropertySourceLocator.loadNacosDataIfPresent(NacosPropertySourceLocator.java:179) [spring-cloud-alibaba-nacos-config-0.9.0.RELEASE.jar!/:0.9.0.RELEASE]
        at org.springframework.cloud.alibaba.nacos.client.NacosPropertySourceLocator.loadApplicationConfiguration(NacosPropertySourceLocator.java:155) [spring-cloud-alibaba-nacos-config-0.9.0.RELEASE.jar!/:0.9.0.RELEASE]
        at org.springframework.cloud.alibaba.nacos.client.NacosPropertySourceLocator.locate(NacosPropertySourceLocator.java:88) [spring-cloud-alibaba-nacos-config-0.9.0.RELEASE.jar!/:0.9.0.RELEASE]
        at org.springframework.cloud.bootstrap.config.PropertySourceBootstrapConfiguration.initialize(PropertySourceBootstrapConfiguration.java:94) [spring-cloud-context-2.0.0.RELEASE.jar!/:2.0.0.RELEASE]
        at org.springframework.boot.SpringApplication.applyInitializers(SpringApplication.java:628) [spring-boot-2.0.8.RELEASE.jar!/:2.0.8.RELEASE]
        at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:364) [spring-boot-2.0.8.RELEASE.jar!/:2.0.8.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:305) [spring-boot-2.0.8.RELEASE.jar!/:2.0.8.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1242) [spring-boot-2.0.8.RELEASE.jar!/:2.0.8.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1230) [spring-boot-2.0.8.RELEASE.jar!/:2.0.8.RELEASE]
        at com.tba.sc.gateway.GatewayApplication.main(GatewayApplication.java:15) [classes!/:1.0-SNAPSHOT]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_91]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_91]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_91]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_91]
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) [tba-gateway.jar:1.0-SNAPSHOT]
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) [tba-gateway.jar:1.0-SNAPSHOT]
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) [tba-gateway.jar:1.0-SNAPSHOT]
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51) [tba-gateway.jar:1.0-SNAPSHOT]
Caused by: java.nio.charset.MalformedInputException: Input length = 1
        at java.nio.charset.CoderResult.throwException(Unknown Source) ~[na:1.8.0_91]
        at sun.nio.cs.StreamDecoder.implRead(Unknown Source) ~[na:1.8.0_91]
        at sun.nio.cs.StreamDecoder.read(Unknown Source) ~[na:1.8.0_91]
        at java.io.InputStreamReader.read(Unknown Source) ~[na:1.8.0_91]
        at org.yaml.snakeyaml.reader.UnicodeReader.read(UnicodeReader.java:125) ~[snakeyaml-1.19.jar!/:na]
        at org.yaml.snakeyaml.reader.StreamReader.update(StreamReader.java:223) ~[snakeyaml-1.19.jar!/:na]

2. 处理方式

在nacos中删除中文也可以处理此问题,但不是最佳方案。
在idea中启动项目时,因为 idea相关配置中设置UTF-8的文件编码格式file.encoding=utf-8。打包运行后,该设置需要手动指定,如下

java  -D‘file.encoding=utf-8‘ -D‘server.port=10001‘ -jar .\tba-gateway.jar 
  • 注意其中JVM参数需要放在-jar命令前
  • windows平台需要使用‘‘符号包裹参数,否则会有如下异常
错误: 找不到或无法加载主类 .encoding=utf-8
 
 

NACOS MalformedInputException 无法读取中文配置问题

标签:nic   osd   设置   java   fine   initial   cto   uil   nconf   

原文地址:https://www.cnblogs.com/exmyth/p/12451923.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!