SpringBoot配置文件格式

1.現在項目pox.xml引入springBoot依賴代碼如下

  <!-- Spring Boot 依賴 -->
  <dependencies>
    <dependency>        
	  <groupId>org.springframework.boot</groupId>        
	  <artifactId>spring-boot-starter-web</artifactId>    
	  </dependency>
  </dependencies>
  <parent>    
	  <groupId>org.springframework.boot</groupId>    
	  <artifactId>spring-boot-starter-parent</artifactId>    
	  <version>2.1.3.RELEASE</version>
  </parent>

2.Spring Boot 支持 properties 和 yaml 兩種格式的文件,文件名分別對應 application.properties 和 application.yml
application.properties格式

server.port: 8082  
server.servlet.context-path=/api

application.yml格式

server:  
   port: 8080  
servlet:    
   context-path: /api
   multipart:      
   maxFileSize: -1 
tomcat:    
   basedir: /data/tmp    
   max-threads: 1000    
   min-spare-threads: 50  
   connection-timeout: 5000
datasource:    
   url: jdbc:mysql://localhost:3306/jy_test?useUnicode=true&characterEncoding=UTF-8&useSSL=true    
   username: root    
   password: root    
   driverClassName: com.mysql.jdbc.Driver  

yaml 以換行+ 空格 隔開,這裏需要注意的是冒號後面必須空格,否則會報錯。
yaml 文件格式更清晰,更易讀,建議採用 yaml 文件來配置。

若使用tab來代替空格則報錯信息如下

Caused by: org.yaml.snakeyaml.scanner.ScannerException: 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 2, column 1:
    	port: 8080  
    ^

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章