石家庄网站建设价格低,网站空间速度,上海抖音推广,做的网站如何投入搜索引擎在Spring Boot中#xff0c;application.properties 和 application.yml 文件用于配置应用程序的各个方面#xff0c;如服务器端口、数据库连接、日志级别等。这两个文件是Spring Boot的配置文件#xff0c;位于 src/main/resources 目录下。 application.properties 示例 … 在Spring Boot中application.properties 和 application.yml 文件用于配置应用程序的各个方面如服务器端口、数据库连接、日志级别等。这两个文件是Spring Boot的配置文件位于 src/main/resources 目录下。 application.properties 示例 application.properties 文件使用键值对的格式进行配置 # 设置服务器端口
server.port8080
# 数据库配置
spring.datasource.urljdbc:mysql://localhost:3306/mydb
spring.datasource.usernamemyuser
spring.datasource.passwordmypassword
spring.datasource.driver-class-namecom.mysql.cj.jdbc.Driver
# 日志配置
logging.level.rootINFO
logging.level.org.springframework.webDEBUG
logging.level.org.hibernateERROR
# Thymeleaf 配置
spring.thymeleaf.prefixclasspath:/templates/
spring.thymeleaf.suffix.html
spring.thymeleaf.modeHTML
spring.thymeleaf.encodingUTF-8
spring.thymeleaf.cachefalseapplication.yml 示例 application.yml 文件使用 YAMLYet Another Markup Language格式它是一种直观的能够被电脑读取的数据序列化格式并且易于人类阅读。它是JSON的一个超集。 # 设置服务器端口
server:port: 8080
# 数据库配置
spring:datasource:url: jdbc:mysql://localhost:3306/mydbusername: myuserpassword: mypassworddriver-class-name: com.mysql.cj.jdbc.Driver
# 日志配置
logging:level:root: INFOorg.springframework.web: DEBUGorg.hibernate: ERROR
# Thymeleaf 配置
thymeleaf:prefix: classpath:/templates/suffix: .htmlmode: HTMLencoding: UTF-8cache: false在 application.yml 文件中可以使用缩进来表示层级关系使得配置更加清晰。 注意事项 - application.properties 和 application.yml 可以同时存在但是 application.properties 中的配置会覆盖 application.yml 中的同名配置。 - application.yml 支持数组或列表的配置例如myprops: [~, ~]。 - 在 application.yml 中冒号 : 后面必须有一个空格。 - application.yml 支持多文档块可以在同一个文件中分隔多个配置文档。 选择 application.properties 还是 application.yml 主要取决于个人喜好和项目需求。YAML格式在处理复杂配置时可能更加直观和易于管理。