这几天在学习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. liunx驱动----USB驱动

    现象:把usb设备接入电脑 1.Windows发现设备 2.跳出一个对话框提示安装驱动程序 问1:既然没有驱动程序,为什么了够知道是什么驱动了?? 答1:Windows里面已经有了usb总线驱动程序, ...

  2. C#发送内置图片的html格式邮件的代码

    将写内容过程经常用的内容段备份一次,下面的内容是关于C#发送内置图片的html格式邮件的内容,应该对码农们也有用处.MailMessage m = new MailMessage();m.Subjec ...

  3. Oarcle之集合操作

    计算字段(列):不在于表中,通过x.÷操作和列进行计算得到的列: 获取员工的年薪 select (ename || '的年薪为:' || sal*12) info from emp; *info 为表 ...

  4. Java集合类学习笔记2

    二,具体的集合 集合类型 描述 ArrayList 一种可以动态增长和缩减的索引序列 LinkedList 一种可以在任何位置进行高效地插入和删除操作的有序序列 ArrayDeque 一种用循环数组实 ...

  5. vue的三种通信方式

    一 确定组件关系二 使用第一步确定的组件关系在下面找到使用方法 1 父子通信(子组件使用父组件数据渲染) a) 在 子组件 中添加props props: [自定义prop名字] b) 在子组件中把自 ...

  6. latch releae overview

    1. MainFsmStates add MAIN_FSM_LATCH_OPEN_FOR_DOOR_CLOSE 2. mb_PcuTriggerReInit = TRUE; /* start PCU ...

  7. 使用CA签发的服务器证书搭建Tomcat双向SSL认证服务

    第一部分,先说证书的申请. 这步是要到正规的CA公司申请正式的设备证书必须走的步骤. 1.先生成证书的密钥对 打开命令行,切换到某个自己新建的目录下,执行如下命令 keytool -genkey -k ...

  8. 其他shell

    dash shell Debian的dash shell的历史很有趣.它是ash shell的直系后代,而ash shell则是Unix系统上原来 的Bourne shell的简化版本(参见第1章). ...

  9. 删除zabbix数据库日志

    #!/bin/bashuser="root"passwd="361way"timedate=`date -d $(date -d "-90 day&q ...

  10. springboot使用validation 插件做数据校验

    不多说废话. 首先,我们需要在入参实体对象中,使用注解,控制 @Datapublic class UpdateShufflingRequest { private String shuffling_l ...