使用springboot默认创建项目,是application.properties,改成yml格式时,需要注意以下几点:
- 注释中不能用中文
- yml格式,采用tree形状,key和value中的“冒号",冒号与值之间要有空格,如 username: root
- 同一级别节点格式要对齐,下面红包部分由于没有对齐,运行项目时报错
spring: datasource: url: jdbc:mysql://127.0.0.1:3306/business?useUnicode=true&characterEncoding=utf-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC username: root password: root driverClassName: com.mysql.cj.jdbc.Driver # use mysql jpa: database: mysql # is show sql show-sql: true mybatis: typeAliasesPackage: com.xj.demo.model mapper-locations: classpath:mapper/*.xml # JWT Object save audience audience: clientId: 098f6bcd4621d373cade4e832627b4f6 # A key that can be replaced by Base64 encryption base64Secret: MDk4ZjZiY2Q0NjIxZDM3M2NhZGU0ZTgzMjYyN2I0ZjY= # The issuing subject of the JWT shall be deposited in the issuer name: springbootapi # Expired 24 hours expiresSecond: 86400 pagehelper: helperDialect: mysql reasonable: true # To minimize or maximize the number of pages when the input page is negative or larger supportMethodsArguments: true params: count:countSql
yml中格式错误,肉眼不太容易找出错误,推荐一个在线查看的工具:http://old.qqe2.com/jsontool/yaml.php
修改正确后的效果