[英]Why doesn't spring-boot connect to local mysql server?
Cant get springboot connected to my localhost mysql database. 无法将springboot连接到我的localhost mysql数据库。
This is my project structure: 这是我的项目结构:
This is the error-log. 这是错误日志。
It is strange that he says: "Access denied for user ''@'localhost' (using password: NO)", but in my application.properties i have written connection: 奇怪的是他说:“访问被拒绝用户'''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
My build.gradle file: 我的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')
}
I am new with springboot, but i can connect to my local database, when i write normal java connection, so why springboot cant? 我是springboot的新手,但我可以连接到我的本地数据库,当我写正常的java连接时,为什么springboot不能?
I suspect this is because of these properties: 我怀疑这是因为这些属性:
spring.datasource.data-username=root
spring.datasource.data-password=stepin
Try to replace them by 尝试替换它们
spring.datasource.username=root
spring.datasource.password=stepin
It's possible to have 2 different users for executing DDL and DML operations. 可以有2个不同的用户来执行DDL和DML操作。 You specified the second and didn't provide the first.
你指定了第二个并没有提供第一个。
Quote from https://github.com/spring-projects/spring-boot/blob/master/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc : 引自https://github.com/spring-projects/spring-boot/blob/master/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc :
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.