SpringBoot笔记:核心配置文件application.properties

创建好SpringBoot工程后,会在resources文件夹下自动创建一个application.properties文件,这个文件就是SpringBoot的核心配置文件。 如果不想使用默认创建的application.properties格式的配置文件,SpringBoot还支持application.yml或application.yaml格式的文件,不过需要注意的是,核心配置文件只能有一个,并且文件名只能是这三种之一,是一个固定的约定项。

常用配置项

# 设置自带的Tomcat的端口号,默认为8080
server.port=8081

# 设置所有请求的url前缀,必须以斜杠/开头
server.servlet.context-path=/api

# 连接数据库的配置信息
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/springboot?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8
spring.datasource.username=root
spring.datasource.password=123456

# 配置MyBtis中Mapper.xml的文件路径
mybatis.mapper-locations=classpath:mapper/*.xml

# 设置Servlet编码格式
server.servlet.encoding.enabled=true
server.servlet.encoding.force=true
server.servlet.encoding.charset=UTF-8

# MVC中设置view路径的前后缀
spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp

# 设置Redis的连接配置信息
spring.redis.host=xxx.xxx.xxx.xxx
spring.redis.port=6379
spring.redis.password=123456

IDEA警告处理 :如果在使用@ConfigurationProperties注解时IDEA弹出警告“Spring Boot Configuration Annotation Processor not configured”,只需要在pom.xml中添加如下依赖即可。

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-configuration-processor</artifactId>
    <optional>true</optional>
</dependency>
posted @ 2022-11-02 13:12  山上下了雪-bky  阅读(572)  评论(0编辑  收藏  举报