天天看點

【SpringBoot】啟動SpringBoot并且配置資料庫連接配接

目錄

​​一、版本介紹​​

         ​​二、gradle配置​​

         ​​三、properties配置​​

​​四、啟動項目 ​​

一、版本介紹

1. SpringBoot版本2.4.8

2. Gradel版本6.8.3

二、gradle配置

plugins {
  id 'org.springframework.boot' version '2.4.8'
  id 'io.spring.dependency-management' version '1.0.11.RELEASE'
  id 'java'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

configurations {
  compileOnly {
    extendsFrom annotationProcessor
  }
}

repositories {
  maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
  maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' }
  mavenCentral()
}

dependencies {
  implementation 'org.springframework.boot:spring-boot-starter-web'
  implementation 'org.springframework.boot:spring-boot-starter-actuator'
  implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
  implementation 'org.springframework.boot:spring-boot-starter-data-redis'
  implementation 'org.springframework.boot:spring-boot-starter-jdbc'
  implementation 'org.springframework.kafka:spring-kafka'
  compileOnly 'org.projectlombok:lombok'
  runtimeOnly 'io.micrometer:micrometer-registry-prometheus'
  runtimeOnly 'mysql:mysql-connector-java'
  annotationProcessor 'org.projectlombok:lombok'
  testImplementation 'org.springframework.boot:spring-boot-starter-test'
  testImplementation 'org.springframework.kafka:spring-kafka-test'
}

test {
  useJUnitPlatform()
}      

三、properties配置

server.port=8080

# springboot啟動出現Access to DialectResolutionInfo cannot be null when ‘hibernate.dialect‘ not set,加上這個
spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/demo?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false
spring.datasource.username=root
spring.datasource.password=      

四、啟動項目 

五、參考資料