这几天在学习springboot的微服务项目,在配置文件方面也想尝试下新的yml配置,就想把原来项目properties写的文件转换成yml试一下(老项目是之前检出在了eclipse里面),结果写好了yml配置文件,项目启动时候报了如下错误:

Exception in thread "main" while scanning for the next token

found character '\t(TAB)' that cannot start any token. (Do not use \t(TAB) for indentation)
 in 'reader', line 9, column 3:
      dubbo:
      ^

at org.yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens(ScannerImpl.java:420)

at org.yaml.snakeyaml.scanner.ScannerImpl.checkToken(ScannerImpl.java:226)

.......

原因是因为我在yml配置文件中用了Tab键来缩进,所以导致spring启动读取yml配置文件不能正确读取。

注意我在上面标红的地方,yml配置中使用Tab来缩进确实不符合yml的语法规则,但是我试了一下在另一个开发工具IDEA中yml配置使用Tab来缩进项目启动是没有报错的,可能是是IDEA开发工具比较厉害的一点,不过我们还是要注意尽量不要使用Tab来缩进。

还有很多类似的启动报错,很可能就是你的yml配置文件里面有问题,这个时候我们就要仔细检查下yml文件书写是否符合规范,贴一个YAML语言教程地址:http://www.ruanyifeng.com/blog/2016/07/yaml.html?f=tt
里面有写yml文件的语法规则,大家可以去看看。

上面是可以从代码报错中看出,当时我的项目中报错如下:

Caused by: org.yaml.snakeyaml.scanner.ScannerException: while scanning a simple key
 in 'reader', line 7, column 3:
      serviceUrl.defaultZone:http://lo ...
      ^
could not find expected ':'
 in 'reader', line 7, column 55:
     ... ne:http://localhost:8080/eureka/
                                         ^

改正方法:yml文件中key: value,在value之前加上空格,我的代码是eureka.client.serviceUrl.defaultZone: http://localhost:8080/eureka/

ok

yml配置文件读取出错 Exception in thread "main" while scanning for the next token found character '\t(TAB)'的更多相关文章

  1. 启动elasticsearch的时候报出Exception in thread "main" SettingsException[Failed to load settings from /usr/local/elasticsearch/config/elasticsearch.yml]; nested: MarkedYAMLException[while scanning a simple ke

    故障现象: [elasticsearch@tiantianml- ~]$ /usr/local/elasticsearch/bin/elasticsearch Exception in thread ...

  2. grails框架中读取txt文件内容将内容转换为json格式,出现异常Exception in thread "main" org.json.JSONException: A JSONObject text must begin with '{' at character 1 of [...]

    Exception in thread "main" org.json.JSONException: A JSONObject text must begin with '{' a ...

  3. Exception in thread "main" SettingsException[Failed to load settings from [elasticsearch.yml]]; nested: ElasticsearchParseException[malformed, expected end of settings but encountered additional conte

    D:\elasticsearch\elasticsearch-2.4.0\bin>elasticsearchException in thread "main" Settin ...

  4. Exception in thread "main" java.lang.OutOfMemoryError: Java heap space

    Exception in thread "main" java.lang.OutOfMemoryError: Java heap space解决方法 问题描述 Exception ...

  5. Exception in thread "main" java.nio.channels.NotYetConnectedException

    import java.nio.channels.AsynchronousServerSocketChannel; import java.nio.channels.AsynchronousSocke ...

  6. Exception in thread "main" java.lang.OutOfMemoryError: Java heap space(Java堆空间内存溢出)解决方法

    http://hi.baidu.com/619195553dream/blog/item/be9f12adc1b5a3e71f17a2e9.html问题描述Exception in thread &q ...

  7. ERROR: Field 'PostId' doesn't have a default value Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not execute statement

    例子: Post p = new Post(); p.setPostId(3); p.setPostName("技术"); 在执行数据保持时提示session.save(p); 的 ...

  8. 在运行Hibernate Hello World程序的时候,抛如下错误: view plain Exception in thread "main" org.hibernate.exception.LockAcquisitionException 解决方法

    在运行Hibernate Hello World程序的时候,抛如下错误: Exception in thread "main" org.hibernate.exception.Lo ...

  9. Java中调用c/c++语言出现Exception in thread "main" java.lang.UnsatisfiedLinkError: Test.testPrint(Ljava/lang/String;)V...错误

    错误: Exception in thread "main" java.lang.UnsatisfiedLinkError: Test.testPrint(Ljava/lang/S ...

随机推荐

  1. CentOS7──xxx is not in the sudoers file

    提示"xxx is not in the sudoers file. This incident will be reported.其中 ”XXX“是你的用户名,也就是你的用户名没有权限使用 ...

  2. python -yield理解

    参考:https://foofish.net/iterators-vs-generators.html 从网上看到一个面试题,求最后的输出结果: def add(n, i): return n+ide ...

  3. CCF CSP 201503-2 数字排序 (map+自定义排序)

    题目链接:http://118.190.20.162/view.page?gpid=T26 返回试题列表 问题描述 试题编号: 201503-2 试题名称: 数字排序 时间限制: 1.0s 内存限制: ...

  4. Java SE中的Synchronized

    1 引言 在多线程并发的编程中Synchronized一直是元老级的角色,很多人会称呼它为重量级锁,但是随着Java SE1.6对Synchronized进行了各种优化以后,有些情况下它并不那么重了. ...

  5. GoldenGate for bigdata 12.3.2.1版本新特性

    在Oracle Tenical Network(OTN)上已经可以下载到最新的ogg4bd版本,地址如下:http://www.oracle.com/technetwork/middleware/go ...

  6. 画多边形form并填充背景色(可以实现圆角边框 有锯齿)

    public Form1() { InitializeComponent(); this.BackColor = ColorTranslator.FromHtml("#F7F1F1" ...

  7. 多线程threading 的使用

    在Python3中,通过threading模块提供线程的功能.原来的thread模块已废弃.但是threading模块中有个Thread类(大写的T,类名),是模块中最主要的线程类,一定要分清楚了,千 ...

  8. PL/SQL数据类型

    在定义变量或常量时,必须要指定一个数据类型,PL/SQL是一种静态类型化的程序设计语言,静态类型化又称为强类型化,也就是说类型会在编译时而不是在运行时被检查,这样在编译时便能发现类型错误,以便增强程序 ...

  9. Educational Codeforces Round 48 (Rated for Div. 2)

    http://codeforces.com/contest/1016 A. 没想到这个也会TLE,太粗心了 B. 暴力就好了,多情况讨论又出错... 思路跟我一样的解法   为什么我做了那么多讨论,原 ...

  10. Java基础学习-Eclipse综述和运算符的使用

    1.Eclipse的概述(磨刀不误砍柴工)       -Eclipse是一个IDE(集成开发环境)         -IDE(Intergrated Development Environment) ...