[英]Why doesn't spring-boot connect to local mysql server?
無法將springboot連接到我的localhost mysql數據庫。
這是我的項目結構:
這是錯誤日志。
奇怪的是他說:“訪問被拒絕用戶'''localhost'(使用密碼:NO)”,但是在我的application.properties中我寫了連接:
server.port=8080
spring.main.banner-mode=off
spring.thymeleaf.cache=false
spring.freemarker.cache=false
spring.groovy.template.cache=false
spring.datasource.url=jdbc:mysql://localhost:3306/user?autoReconnect=true&useSSL=false
spring.datasource.data-username=root
spring.datasource.data-password=stepin
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
我的build.gradle文件:
buildscript {
ext {
springBootVersion = '1.4.1.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle- plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'spring-boot'
jar {
baseName = 'databaseaccess'
version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-web')
compile('mysql:mysql-connector-java')
runtime("com.h2database:h2")
testCompile('org.springframework.boot:spring-boot-starter-test')
}
我是springboot的新手,但我可以連接到我的本地數據庫,當我寫正常的java連接時,為什么springboot不能?
我懷疑這是因為這些屬性:
spring.datasource.data-username=root
spring.datasource.data-password=stepin
嘗試替換它們
spring.datasource.username=root
spring.datasource.password=stepin
可以有2個不同的用戶來執行DDL和DML操作。 你指定了第二個並沒有提供第一個。
spring.datasource.data= # Data (DML) script resource reference.
spring.datasource.data-username= # User of the database to execute DML scripts (if different).
spring.datasource.data-password= # Password of the database to execute DML scripts (if different).
spring.datasource.username=
spring.datasource.password= # Login password of the database.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.