微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

java – 为什么spring-boot连接到本地mysql服务器?

无法将springboot连接到我的localhost mysql数据库.
这是我的项目结构:

enter image description here

这是错误日志.

enter image description here

奇怪的是他说:“访问被拒绝用户”’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个不同的用户来执行DDLDML操作.你指定了第二个并没有提供第一个.

引自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.

原文地址:https://www.jb51.cc/mysql/432873.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐