yml 文件的中文注释导致 Failed to load property source from location 'classpath:/application.yml'

以前项目可以正常运行。
今天重新打开项目运行,出现了下面异常:

23:56:12.102 [main] DEBUG org.springframework.boot.context.logging.ClasspathLoggingApplicationListener - Application failed to start with classpath: [file:/F:/Install/JavaJDK/JDKInstall/jdk1.8.0_181/jre/lib/charsets.jar, file:/F:/Install/JavaJDK/JDKInstall/jdk1.8.0_181/jre/lib/deploy.jar, file:/F:/Install/JavaJDK/JDKInstall/jdk1.8.0_181/jre/lib/ext/access-bridge-64.jar, file:/F:/Install/JavaJDK/JDKInstall/jdk1.8.0_181/jre/lib/ext/cldrdata.jar, file:/F:/Install/JavaJDK/JDKInstall/jdk1.8.0_181/jre/lib/ext/dnsns.jar, file:/F:/Install/JavaJDK/JDKInstall/jdk1.8.0_181/jre/lib/ext/jaccess.jar, file:/F:/Install/JavaJDK/JDKInstall/jdk1.8.0_181/jre/lib/ext/jfxrt.jar, file:/F:/Install/JavaJDK/JDKInstall/jdk1.8.0_181/jre/lib/ext/localedata.jar, file:/F:/Install/JavaJDK/JDKInstall/jdk1.8.0_181/jre/lib/ext/nashorn.jar, file:/F:/Install/JavaJDK/JDKInstall/jdk1.8.0_181/jre/lib/ext/sunec.jar, file:/F:/Install/JavaJDK/JDKInstall/jdk1.8.0_181/jre/lib/ext/sunjce_provider.jar, file:/F:/Install/JavaJDK/JDKInstall/jdk1.8.0_181/jre/lib/ext/sunmscapi.jar, file:/F:/Install/JavaJDK/JDKInstall/jdk1.8.0_181/jre/lib/ext/sunpkcs11.jar, file:/F:/Install/JavaJDK/JDKInstall/jdk1.8.0_181/jre/lib/ext/zipfs.jar, file:/F:/Install/JavaJDK/JDKInstall/jdk1.8.0_181/jre/lib/javaws.jar, file:/F:/Install/JavaJDK/JDKInstall/jdk1.8.0_181/jre/lib/jce.jar, file:/F:/Install/JavaJDK/JDKInstall/jdk1.8.0_181/jre/lib/jfr.jar, file:/F:/Install/JavaJDK/JDKInstall/jdk1.8.0_181/jre/lib/jfxswt.jar, file:/F:/Install/JavaJDK/JDKInstall/jdk1.8.0_181/jre/lib/jsse.jar, file:/F:/Install/JavaJDK/JDKInstall/jdk1.8.0_181/jre/lib/management-agent.jar, file:/F:/Install/JavaJDK/JDKInstall/jdk1.8.0_181/jre/lib/plugin.jar, file:/F:/Install/JavaJDK/JDKInstall/jdk1.8.0_181/jre/lib/resources.jar, file:/F:/Install/JavaJDK/JDKInstall/jdk1.8.0_181/jre/lib/rt.jar, file:/F:/Install/CompilerWorkspace/IDEA2/mybatis/springboot_mybatis/target/classes/, file:/F:/Install/Apache/apache-maven-3.5.4/repository/org/springframework/boot/spring-boot-starter-web/2.1.0.RELEASE/spring-boot-starter-web-2.1.0.RELEASE.jar, file:/F:/Install/Apache/apache-maven-3.5.4/repository/org/springframework/boot/spring-boot-starter/2.1.0.RELEASE/spring-boot-starter-2.1.0.RELEASE.jar, file:/F:/Install/Apache/apache-maven-3.5.4/repository/org/springframework/boot/spring-boot/2.1.0.RELEASE/spring-boot-2.1.0.RELEASE.jar, file:/F:/Install/Apache/apache-maven-3.5.4/repository/org/springframework/boot/spring-boot-autoconfigure/2.1.0.RELEASE/spring-boot-autoconfigure-2.1.0.RELEASE.jar, file:/F:/Install/Apache/apache-maven-3.5.4/repository/org/springframework/boot/spring-boot-starter-logging/2.1.0.RELEASE/spring-boot-starter-logging-2.1.0.RELEASE.jar, file:/F:/Install/Apache/apache-maven-3.5.4/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar, file:/F:/Install/Apache/apache-maven-3.5.4/repository/ch/qos/logback/logback-core/1.2.3/logback-core-1.2.3.jar, file:/F:/Install/Apache/apache-maven-3.5.4/repository/org/apache/logging/log4j/log4j-to-slf4j/2.11.1/log4j-to-slf4j-2.11.1.jar, file:/F:/Install/Apache/apache-maven-3.5.4/repository/org/apache/logging/log4j/log4j-api/2.11.1/log4j-api-2.11.1.jar, file:/F:/Install/Apache/apache-maven-3.5.4/repository/org/slf4j/jul-to-slf4j/1.7.25/jul-to-slf4j-1.7.25.jar, file:/F:/Install/Apache/apache-maven-3.5.4/repository/javax/annotation/javax.annotation-api/1.3.2/javax.annotation-api-1.3.2.jar, file:/F:/Install/Apache/apache-maven-3.5.4/repository/org/yaml/snakeyaml/1.23/snakeyaml-1.23.jar, file:/F:/Install/Apache/apache-maven-3.5.4/repository/org/springframework/boot/spring-boot-starter-json/2.1.0.RELEASE/spring-boot-starter-json-2.1.0.RELEASE.jar, file:/F:/Install/Apache/apache-maven-3.5.4/repository/com/fasterxml/jackson/core/jackson-databind/2.9.7/jackson-databind-2.9.7.jar, file:/F:/Install/Apache/apache-maven-3.5.4/repository/com/fasterxml/jackson/core/jackson-annotations/2.9.0/jackson-annotations-2.9.0.jar, file:/F:/Install/Apache/apache-maven-3.5.4/repository/com/fasterxml/jackson/core/jackson-core/2.9.7/jackson-core-2.9.7.jar, file:/F:/Install/Apache/apache-maven-3.5.4/repository/com/fasterxml/jackson/datatype/jackson-datatype-jdk8/2.9.7/jackson-datatype-jdk8-2.9.7.jar, file:/F:/Install/Apache/apache-maven-3.5.4/repository/com/fasterxml/jackson/datatype/jackson-datatype-jsr310/2.9.7/jackson-datatype-jsr310-2.9.7.jar, file:/F:/Install/Apache/apache-maven-3.5.4/repository/com/fasterxml/jackson/module/jackson-module-parameter-names/2.9.7/jackson-module-parameter-names-2.9.7.jar, file:/F:/Install/Apache/apache-maven-3.5.4/repository/org/springframework/boot/spring-boot-starter-tomcat/2.1.0.RELEASE/spring-boot-starter-tomcat-2.1.0.RELEASE.jar, file:/F:/Install/Apache/apache-maven-3.5.4/repository/org/apache/tomcat/embed/tomcat-embed-core/9.0.12/tomcat-embed-core-9.0.12.jar, file:/F:/Install/Apache/apache-maven-3.5.4/repository/org/apache/tomcat/embed/tomcat-embed-el/9.0.12/tomcat-embed-el-9.0.12.jar, file:/F:/Install/Apache/apache-maven-3.5.4/repository/org/apache/tomcat/embed/tomcat-embed-websocket/9.0.12/tomcat-embed-websocket-9.0.12.jar, file:/F:/Install/Apache/apache-maven-3.5.4/repository/org/hibernate/validator/hibernate-validator/6.0.13.Final/hibernate-validator-6.0.13.Final.jar, file:/F:/Install/Apache/apache-maven-3.5.4/repository/javax/validation/validation-api/2.0.1.Final/validation-api-2.0.1.Final.jar, file:/F:/Install/Apache/apache-maven-3.5.4/repository/org/jboss/logging/jboss-logging/3.3.2.Final/jboss-logging-3.3.2.Final.jar, file:/F:/Install/Apache/apache-maven-3.5.4/repository/com/fasterxml/classmate/1.4.0/classmate-1.4.0.jar, file:/F:/Install/Apache/apache-maven-3.5.4/repository/org/springframework/spring-web/5.1.2.RELEASE/spring-web-5.1.2.RELEASE.jar, file:/F:/Install/Apache/apache-maven-3.5.4/repository/org/springframework/spring-beans/5.1.2.RELEASE/spring-beans-5.1.2.RELEASE.jar, file:/F:/Install/Apache/apache-maven-3.5.4/repository/org/springframework/spring-webmvc/5.1.2.RELEASE/spring-webmvc-5.1.2.RELEASE.jar, file:/F:/Install/Apache/apache-maven-3.5.4/repository/org/springframework/spring-aop/5.1.2.RELEASE/spring-aop-5.1.2.RELEASE.jar, file:/F:/Install/Apache/apache-maven-3.5.4/repository/org/springframework/spring-context/5.1.2.RELEASE/spring-context-5.1.2.RELEASE.jar, file:/F:/Install/Apache/apache-maven-3.5.4/repository/org/springframework/spring-expression/5.1.2.RELEASE/spring-expression-5.1.2.RELEASE.jar, file:/F:/Install/Apache/apache-maven-3.5.4/repository/org/mybatis/spring/boot/mybatis-spring-boot-starter/1.3.2/mybatis-spring-boot-starter-1.3.2.jar, file:/F:/Install/Apache/apache-maven-3.5.4/repository/org/springframework/boot/spring-boot-starter-jdbc/2.1.0.RELEASE/spring-boot-starter-jdbc-2.1.0.RELEASE.jar, file:/F:/Install/Apache/apache-maven-3.5.4/repository/com/zaxxer/HikariCP/3.2.0/HikariCP-3.2.0.jar, file:/F:/Install/Apache/apache-maven-3.5.4/repository/org/springframework/spring-jdbc/5.1.2.RELEASE/spring-jdbc-5.1.2.RELEASE.jar, file:/F:/Install/Apache/apache-maven-3.5.4/repository/org/springframework/spring-tx/5.1.2.RELEASE/spring-tx-5.1.2.RELEASE.jar, file:/F:/Install/Apache/apache-maven-3.5.4/repository/org/mybatis/spring/boot/mybatis-spring-boot-autoconfigure/1.3.2/mybatis-spring-boot-autoconfigure-1.3.2.jar, file:/F:/Install/Apache/apache-maven-3.5.4/repository/org/mybatis/mybatis/3.4.6/mybatis-3.4.6.jar, file:/F:/Install/Apache/apache-maven-3.5.4/repository/org/mybatis/mybatis-spring/1.3.2/mybatis-spring-1.3.2.jar, file:/F:/Install/Apache/apache-maven-3.5.4/repository/mysql/mysql-connector-java/8.0.13/mysql-connector-java-8.0.13.jar, file:/F:/Install/Apache/apache-maven-3.5.4/repository/org/slf4j/slf4j-api/1.7.25/slf4j-api-1.7.25.jar, file:/F:/Install/Apache/apache-maven-3.5.4/repository/org/springframework/spring-core/5.1.2.RELEASE/spring-core-5.1.2.RELEASE.jar, file:/F:/Install/Apache/apache-maven-3.5.4/repository/org/springframework/spring-jcl/5.1.2.RELEASE/spring-jcl-5.1.2.RELEASE.jar, file:/F:/Install/CompilerInstall/IntelliJ%20IDEA%202018.2.4/lib/idea_rt.jar]
23:56:12.672 [background-preinit] DEBUG org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator - Loaded expression factory via original TCCL
23:56:12.692 [background-preinit] DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator as ValidatorFactory-scoped message interpolator.
23:56:12.692 [background-preinit] DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.hibernate.validator.internal.engine.resolver.TraverseAllTraversableResolver as ValidatorFactory-scoped traversable resolver.
23:56:12.692 [background-preinit] DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.hibernate.validator.internal.util.ExecutableParameterNameProvider as ValidatorFactory-scoped parameter name provider.
23:56:12.692 [background-preinit] DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.hibernate.validator.internal.engine.DefaultClockProvider as ValidatorFactory-scoped clock provider.
23:56:12.692 [background-preinit] DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.hibernate.validator.internal.engine.scripting.DefaultScriptEvaluatorFactory as ValidatorFactory-scoped script evaluator factory.
23:56:13.637 [main] ERROR org.springframework.boot.SpringApplication - Application run failed
java.lang.IllegalStateException: Failed to load property source from location 'classpath:/application.yml'
	at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:554)
	at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.loadForFileExtension(ConfigFileApplicationListener.java:500)
	at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:467)
	at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.lambda$null$6(ConfigFileApplicationListener.java:448)
	at java.lang.Iterable.forEach(Iterable.java:75)
	at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.lambda$load$7(ConfigFileApplicationListener.java:447)
	at java.lang.Iterable.forEach(Iterable.java:75)
	at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:444)
	at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:332)
	at org.springframework.boot.context.config.ConfigFileApplicationListener.addPropertySources(ConfigFileApplicationListener.java:207)
	at org.springframework.boot.context.config.ConfigFileApplicationListener.postProcessEnvironment(ConfigFileApplicationListener.java:190)
	at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEnvironmentPreparedEvent(ConfigFileApplicationListener.java:177)
	at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEvent(ConfigFileApplicationListener.java:163)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
	at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:75)
	at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
	at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:347)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:306)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
	at com.kaven.springboot_mybatis.SpringbootMybatisApplication.main(SpringbootMybatisApplication.java:12)
Caused by: org.yaml.snakeyaml.error.YAMLException: java.nio.charset.MalformedInputException: Input length = 1
	at org.yaml.snakeyaml.reader.StreamReader.update(StreamReader.java:218)
	at org.yaml.snakeyaml.reader.StreamReader.ensureEnoughData(StreamReader.java:176)
	at org.yaml.snakeyaml.reader.StreamReader.ensureEnoughData(StreamReader.java:171)
	at org.yaml.snakeyaml.reader.StreamReader.peek(StreamReader.java:126)
	at org.yaml.snakeyaml.scanner.ScannerImpl.scanToNextToken(ScannerImpl.java:1177)
	at org.yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens(ScannerImpl.java:287)
	at org.yaml.snakeyaml.scanner.ScannerImpl.checkToken(ScannerImpl.java:227)
	at org.yaml.snakeyaml.parser.ParserImpl$ParseImplicitDocumentStart.produce(ParserImpl.java:195)
	at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:158)
	at org.yaml.snakeyaml.parser.ParserImpl.checkEvent(ParserImpl.java:148)
	at org.yaml.snakeyaml.composer.Composer.checkNode(Composer.java:72)
	at org.yaml.snakeyaml.constructor.BaseConstructor.checkData(BaseConstructor.java:112)
	at org.yaml.snakeyaml.Yaml$1.hasNext(Yaml.java:542)
	at org.springframework.beans.factory.config.YamlProcessor.process(YamlProcessor.java:161)
	at org.springframework.beans.factory.config.YamlProcessor.process(YamlProcessor.java:134)
	at org.springframework.boot.env.OriginTrackedYamlLoader.load(OriginTrackedYamlLoader.java:75)
	at org.springframework.boot.env.YamlPropertySourceLoader.load(YamlPropertySourceLoader.java:50)
	at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.loadDocuments(ConfigFileApplicationListener.java:572)
	at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:526)
	... 23 common frames omitted
Caused by: java.nio.charset.MalformedInputException: Input length = 1
	at java.nio.charset.CoderResult.throwException(CoderResult.java:281)
	at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:339)
	at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
	at java.io.InputStreamReader.read(InputStreamReader.java:184)
	at org.yaml.snakeyaml.reader.UnicodeReader.read(UnicodeReader.java:125)
	at org.yaml.snakeyaml.reader.StreamReader.update(StreamReader.java:183)
	... 41 common frames omitted

异常信息很明显,问题在 yml 文件上。

application.yml 如下:

server:
  port: 8080

spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://127.0.0.1:3306/kaven?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=GMT-8
    username: root

mybatis:
  mapper-locations: classpath:mapper/*.xml
  #中文
  type-aliases-package: com.kaven.springboot_mybatis.domin #中文

百度了很多博客,基本上都是说注释要用 #,而不是 // 这个问题。
但是我用的就是 # 啊。
还有就是空格的问题 ,按照博客说的要求我重新敲了一遍。
不过还是出现上面的异常。

经过很多次测试,把 yml 文件中的注释改成非中文就能正常运行了。

application.yml 如下:

server:
  port: 8080

spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://127.0.0.1:3306/kaven?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=GMT-8
    username: root

mybatis:
  mapper-locations: classpath:mapper/*.xml
  #1
  type-aliases-package: com.kaven.springboot_mybatis.domin #1

运行结果如下:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.1.0.RELEASE)

2018-11-19 00:10:40.868  INFO 7624 --- [           main] c.k.s.SpringbootMybatisApplication       : Starting SpringbootMybatisApplication on DESKTOP-1EB3JGB with PID 7624 (F:\Install\CompilerWorkspace\IDEA2\mybatis\springboot_mybatis\target\classes started by Kaven in F:\Install\CompilerWorkspace\IDEA2\mybatis\springboot_mybatis)
2018-11-19 00:10:40.878  INFO 7624 --- [           main] c.k.s.SpringbootMybatisApplication       : No active profile set, falling back to default profiles: default
2018-11-19 00:10:43.941  INFO 7624 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2018-11-19 00:10:43.971  INFO 7624 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2018-11-19 00:10:43.971  INFO 7624 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/9.0.12
2018-11-19 00:10:43.981  INFO 7624 --- [           main] o.a.catalina.core.AprLifecycleListener   : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [F:\Install\JavaJDK\JDKInstall\jdk1.8.0_181\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;F:\Install\JavaJDK\JDKInstall\jdk1.8.0_181\bin;F:\Install\JavaJDK\JDKInstall\jdk1.8.0_181\jre\bin;F:\Install\Apache\apache-tomcat-9.0.12\lib;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\MySQL\MySQL Utilities 1.6\;F:\Install\Apache\apache-maven-3.5.4\bin;C:\Program Files\MySQL\MySQL Server 5.7\bin;F:\Install\web\nodejsInstall\;F:\Install\VersionControlSystem\GitInstall\Git\cmd;F:\Install\DataBase\RedisInstall;C:\Users\Kaven\AppData\Local\Microsoft\WindowsApps;C:\Users\Kaven\AppData\Roaming\npm;.]
2018-11-19 00:10:44.171  INFO 7624 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2018-11-19 00:10:44.171  INFO 7624 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 3104 ms
2018-11-19 00:10:44.252  INFO 7624 --- [           main] o.s.b.w.servlet.ServletRegistrationBean  : Servlet dispatcherServlet mapped to [/]
2018-11-19 00:10:44.260  INFO 7624 --- [           main] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-11-19 00:10:44.261  INFO 7624 --- [           main] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-11-19 00:10:44.261  INFO 7624 --- [           main] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'formContentFilter' to: [/*]
2018-11-19 00:10:44.261  INFO 7624 --- [           main] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2018-11-19 00:10:44.899  INFO 7624 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2018-11-19 00:10:45.432  INFO 7624 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2018-11-19 00:10:45.442  INFO 7624 --- [           main] c.k.s.SpringbootMybatisApplication       : Started SpringbootMybatisApplication in 5.68 seconds (JVM running for 9.352)

但是我们平时还是习惯用中文注释怎么办呢?不可能改变习惯吧。
既然是 yml 文件出的问题,并且是跟中文问题相关,一般就是 yml 文件编码格式的问题了,我觉得把 yml 文件的编码格式改成 utf-8就可以了。

改编码格式之前,最好还是先把 yml 文件的中文先删掉,改了编码格式再重新复制上去,我之前没有删掉中文,就不允许我改编码格式,我指的是我下面说的这种情况,而不是设置 File Encodings,好像设置 File Encodings 并没有起作用,我不知道下面的设置和设置 File Encodings 有什么区别,有知道的大佬,可以留言告知一下。

编译器下方
在这里插入图片描述
在这里插入图片描述
重启编译器,这种设置会保留,不会又恢复默认设置。
这样设置对于我这个小项目有效,不确保对任何情况都有效。

application.yml 如下:

server:
  port: 8080

spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://127.0.0.1:3306/kaven?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=GMT-8
    username: root

mybatis:
  mapper-locations: classpath:mapper/*.xml
  #中文
  type-aliases-package: com.kaven.springboot_mybatis.domin #中文

程序启动成功:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.1.0.RELEASE)

2018-11-19 00:30:38.943  INFO 6268 --- [           main] c.k.s.SpringbootMybatisApplication       : Starting SpringbootMybatisApplication on DESKTOP-1EB3JGB with PID 6268 (F:\Install\CompilerWorkspace\IDEA2\mybatis\springboot_mybatis\target\classes started by Kaven in F:\Install\CompilerWorkspace\IDEA2\mybatis\springboot_mybatis)
2018-11-19 00:30:38.955  INFO 6268 --- [           main] c.k.s.SpringbootMybatisApplication       : No active profile set, falling back to default profiles: default
2018-11-19 00:30:42.656  INFO 6268 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2018-11-19 00:30:42.685  INFO 6268 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2018-11-19 00:30:42.685  INFO 6268 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/9.0.12
2018-11-19 00:30:42.695  INFO 6268 --- [           main] o.a.catalina.core.AprLifecycleListener   : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [F:\Install\JavaJDK\JDKInstall\jdk1.8.0_181\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;F:\Install\JavaJDK\JDKInstall\jdk1.8.0_181\bin;F:\Install\JavaJDK\JDKInstall\jdk1.8.0_181\jre\bin;F:\Install\Apache\apache-tomcat-9.0.12\lib;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\MySQL\MySQL Utilities 1.6\;F:\Install\Apache\apache-maven-3.5.4\bin;C:\Program Files\MySQL\MySQL Server 5.7\bin;F:\Install\web\nodejsInstall\;F:\Install\VersionControlSystem\GitInstall\Git\cmd;F:\Install\DataBase\RedisInstall;C:\Users\Kaven\AppData\Local\Microsoft\WindowsApps;C:\Users\Kaven\AppData\Roaming\npm;.]
2018-11-19 00:30:42.939  INFO 6268 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2018-11-19 00:30:42.939  INFO 6268 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 3791 ms
2018-11-19 00:30:42.989  INFO 6268 --- [           main] o.s.b.w.servlet.ServletRegistrationBean  : Servlet dispatcherServlet mapped to [/]
2018-11-19 00:30:42.989  INFO 6268 --- [           main] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-11-19 00:30:42.989  INFO 6268 --- [           main] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-11-19 00:30:42.989  INFO 6268 --- [           main] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'formContentFilter' to: [/*]
2018-11-19 00:30:42.989  INFO 6268 --- [           main] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2018-11-19 00:30:43.732  INFO 6268 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2018-11-19 00:30:44.397  INFO 6268 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2018-11-19 00:30:44.397  INFO 6268 --- [           main] c.k.s.SpringbootMybatisApplication       : Started SpringbootMybatisApplication in 7.068 seconds (JVM running for 10.137)

对于我这个小项目,yml 文件中的中文问题暂时算是解决了(不知道以后会不会还有 bug)。

设置 File Encodings :
在这里插入图片描述
在这里插入图片描述
我全部设置为 utf-8 都没有用。
要是有说错的地方,请大家不吝赐教。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ITKaven

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值