spring boot配置文件application.properties配置JPA以及数据源

1.application.properties配置jpa模板

spring.datasource.url=jdbc:mysql://localhost:3306/springboottest?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=Zp970321
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

#jpa setting
spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect

spring.jpa.hibernate.ddl-auto=update

spring.jpa.show-sql=true

注意:url上一定要加上时区serverTimezone=UTC ,否则会报错。

当使用JPA访问数据库时,一定要设置数据库方言

2.application.properties配置Druid数据源

springboot的默认数据源:org.apache.tomcat.jdbc.pool.DateSource

修改数据源为Druid的配置如下:

spring.datasource.type=com.alibaba.druid.pool.DruidDataSource

常用的数据源属性配置如下:

spring.datasource.initSize=5
spring.datasource.minIdle=5
spring.datasource.maxActive=20
spring.datasource.maxWait=6000
spring.datasource.timeBetweenEvictionRunsMillis=60000
spring.datasource.minEvictableIdleTimeMillis=300000

原文地址:https://www.cnblogs.com/z-x-p/p/11491077.html

时间: 2024-08-03 19:36:03

spring boot配置文件application.properties配置JPA以及数据源的相关文章

Spring Boot2 系列教程(四)理解Spring Boot 配置文件 application.properties

在 Spring Boot 中,配置文件有两种不同的格式,一个是 properties ,另一个是 yaml . 虽然 properties 文件比较常见,但是相对于 properties 而言,yaml 更加简洁明了,而且使用的场景也更多,很多开源项目都是使用 yaml 进行配置(例如 Hexo).除了简洁,yaml 还有另外一个特点,就是 yaml 中的数据是有序的,properties 中的数据是无序的,在一些需要路径匹配的配置中,顺序就显得尤为重要(例如我们在 Spring Cloud

Spring boot配置文件application.properties

# =================================================================== # COMMON SPRING BOOT PROPERTIES # # This sample file is provided as a guideline. Do NOT copy it in its # entirety to your own application.               ^^^ # =====================

Spring boot配置文件 application.properties

# =================================================================== # COMMON SPRING BOOT PROPERTIES # # This sample file is provided as a guideline. Do NOT copy it in its # entirety to your own application.               ^^^ # =====================

附录 B. Spring Boot 配置文件 application.properties

#########COMMON SPRING BOOT PROPERTIES ######========CORE PROPERTIES=========== #SPRING CONFIG (ConfigFileApplicationListener) spring.config.name= # config file name (default to 'application') spring.config.location= # location of config file #PROFIL

Spring Boot 配置文件application.properties

#########COMMON SPRING BOOT PROPERTIES ######========CORE PROPERTIES=========== #SPRING CONFIG (ConfigFileApplicationListener) spring.config.name= # config file name (default to 'application') spring.config.location= # location of config file #PROFIL

附录B. Spring Boot 配置文件application.properties

#SPRING CONFIG (ConfigFileApplicationListener) spring.config.name= # config file name (default to 'application') spring.config.location= # location of config file #PROFILES spring.profiles= # comma list of active profiles #APPLICATION SETTINGS (Sprin

spring boot项目application.properties多环境配置文件、jar包外部配置文件

一.简介 spring boot项目application.properties文件存放及使用介绍 二.方法一多环境配置文件 我们一般都会有多个应用环境,开发环境.测试环境.生产环境,各个环境的配置会略有不同,我可以根据这个创建多份配置文件,由主配置文件来控制读取那个子配置 创建spring boot项目后可以同时创建多个.properties文件,只要符合它要求的格式即可 格式:application-{profile}.properties:{profile}是变量用于自定义配置文件名称 分

Spring Boot 项目 application.properties配置说明

#======================================================================================# ★☆★☆★☆★☆★☆ spring boot 配置中心 ★☆★☆★☆★☆★☆#====================================================================================== springBoot application.properties 基

spring boot 配置文件application

场景:在项目部署的过程中,对于spring boot的配置文件一直不很了解,直到项目出现一个莫名其妙的问题——工程classes中的配置文件被覆盖,程序启动总是报错! 1  配置文件的优先级 application.properties大家都不陌生,我们在开发的时候,经常使用它来配置一些可以手动修改而且不用编译的变量,这样的作用在于,打成war包或者jar用于生产环境时,我们可以手动修改环境变量而不用再重新编译. spring boo默认已经配置了很多环境变量,例如,tomcat的默认端口是80