【Spring Boot】Spring Boot项目中application.properties文件配置示例

Spring Boot项目中application.properties文件配置示例

在使用IDEA创建Spring Boot项目后,会在resource目录里边看到生成了一个application.properties文件,该文件用于配置项目的一些常用属性,例如数据源,字符集等。因此,我们展示了一个application.properties文件配置示例,其中包括项目字符集配置、数据源配置。代码如下:

#############################################################################
### 字符集设置
#############################################################################
spring.http.encoding.force=true
spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
server.tomcat.uri-encoding=UTF-8

############################################################################
### 数据源配置
############################################################################
# 数据库地址
spring.datasource.url=jdbc:mariadb://localhost:3306/jdbctemplate
# 用户名
spring.datasource.username=root
# 密码
spring.datasource.password=admin
# 数据库驱动
spring.datasource.driver-class-name=org.mariadb.jdbc.Driver
# 指定连接池中最大的活跃连接数
spring.datasource.tomcat.max-active=20
# 指定数据库最大的空闲连接
spring.datasource.tomcat.max-idle=8
# 指定必须保持连接的最小值
spring.datasource.tomcat.min-idle=8
# 指定启动连接池时,初始建立的连接数量
spring.datasource.tomcat.initial-size=10

##############################################################################
### 热部署配置
##############################################################################
spring.devtools.restart.enabled=true

##############################################################################
### 项目属性配置
##############################################################################
server.port=9999
spring.thymeleaf.cache=false

###########################################################################
### JPA配置
###########################################################################
# 指定数据库类型
spring.jpa.database=mysql
# 指定是否需要在日志中显示SQL语句
spring.jpa.show-sql=true
# 指定自动创建|更新|验证数据库表结构等配置,配置成update
# 表示如果数据库中存在持久化类对应的表就不创建,不存在就创建对应的表
spring.jpa.hibernate.ddl-auto=update
# 指定命名策略
spring.jpa.hibernate.naming.physical-strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy
# 指定数据库方言
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect

其中,我们的字符集设置可以有效避免在调试阶段中出现的Web页面乱码情况,另外我们的数据库采用的是MariaDB数据库。

发布了279 篇原创文章 · 获赞 169 · 访问量 32万+

猜你喜欢

转载自blog.csdn.net/ARPOSPF/article/details/105006863
今日推荐