Java 使用Spring Boot连接MySQL DB时出现问题

Java 使用Spring Boot连接MySQL DB时出现问题,java,mysql,spring,spring-boot,jdbc,Java,Mysql,Spring,Spring Boot,Jdbc,我目前在使用Spring Boot应用程序连接mySQL数据库时遇到一些问题。我一直在尝试连接本地数据库和MAMP服务器(两者都有,结果相同) 奇怪的是,我以前的应用程序从来没有遇到过这个问题,甚至可以打开以前的应用程序,甚至可以毫无问题地连接到MAMP服务器和我的本地DB,即使是今天,所以我不知道为什么会发生这种情况 我不知道你们可能需要多少我的项目,但我只会发布我认为必要的内容,以及堆栈跟踪 谢谢 应用程序属性 spring.datasource.url=jdbc:mysql://local

我目前在使用Spring Boot应用程序连接mySQL数据库时遇到一些问题。我一直在尝试连接本地数据库和MAMP服务器(两者都有,结果相同)

奇怪的是,我以前的应用程序从来没有遇到过这个问题,甚至可以打开以前的应用程序,甚至可以毫无问题地连接到MAMP服务器和我的本地DB,即使是今天,所以我不知道为什么会发生这种情况

我不知道你们可能需要多少我的项目,但我只会发布我认为必要的内容,以及堆栈跟踪

谢谢

应用程序属性

spring.datasource.url=jdbc:mysql://localhost:3306/product?useSSL=false

spring.datasource.username=root

spring.datasource.password=123456

spring.jpa.database=MYSQL

spring.jpa.show sql=false

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.3.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>Grocery</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

4.0.0
org.springframework.boot

java.sql.SQLException:拒绝用户'root'@'localhost'的访问(使用密码:是)
在com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)~[mysql-connector-java-8.0.15.jar:8.0.15]
在com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)~[mysql-connector-java-8.0.15.jar:8.0.15]
在com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)~[mysql-connector-java-8.0.15.jar:8.0.15]
在com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:835)~[mysql-connector-java-8.0.15.jar:8.0.15]
在com.mysql.cj.jdbc.ConnectionImpl.(ConnectionImpl.java:455)~[mysql-connector-java-8.0.15.jar:8.0.15]
在com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240)~[mysql-connector-java-8.0.15.jar:8.0.15]
在com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:199)~[mysql-connector-java-8.0.15.jar:8.0.15]
在com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:136)~[HikariCP-3.2.0.jar:na]
在com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:369)~[HikariCP-3.2.0.jar:na]
在com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:198)~[HikariCP-3.2.0.jar:na]
在com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:467)[HikariCP-3.2.0.jar:na]
在com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:541)[HikariCP-3.2.0.jar:na]
在com.zaxxer.hikari.pool.HikariPool.(HikariPool.java:115)[HikariCP-3.2.0.jar:na]
在com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112)[HikariCP-3.2.0.jar:na]
位于org.springframework.jdbc.datasource.DataSourceUtils.fetchConnection(DataSourceUtils.java:157)[spring-jdbc-5.1.5.RELEASE.jar:5.1.5.RELEASE]
位于org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:115)[spring-jdbc-5.1.5.RELEASE.jar:5.1.5.RELEASE]
位于org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:78)[spring-jdbc-5.1.5.RELEASE.jar:5.1.5.RELEASE]
在org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:324)[spring-jdbc-5.1.5.RELEASE.jar:5.1.5.RELEASE]
在org.springframework.boot.jdbc.EmbeddedDatabaseConnection.isEmbedded(EmbeddedDatabaseConnection.java:123)[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
在org.springframework.boot.autoconfigure.orm.jpa.HibernateDefaultDdlAutoProvider.getDefaultDdlAuto(HibernateDefaultDdlAutoProvider.java:42)[spring-boot-autoconfigure-2.1.3.RELEASE.jar:2.1.3.RELEASE]
在org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration.lambda$getVendorProperties$1(HibernateJpaConfiguration.java:142)[spring-boot-autoconfigure-2.1.3.RELEASE.jar:2.1.3.RELEASE]
在org.springframework.boot.autoconfigure.orm.jpa.HibernateSettings.getDdlAuto(HibernateSettings.java:41)~[spring-boot-autoconfigure-2.1.3.RELEASE.jar:2.1.3.RELEASE]
在org.springframework.boot.autoconfigure.orm.jpa.HibernateProperties.determinatedLauto(HibernateProperties.java:130)~[spring-boot-autoconfigure-2.1.3.RELEASE.jar:2.1.3.RELEASE]
在org.springframework.boot.autoconfigure.orm.jpa.HibernateProperties.getAdditionalProperties(HibernateProperties.java:99)~[spring-boot-autoconfigure-2.1.3.RELEASE.jar:2.1.3.RELEASE]
在org.springframework.boot.autoconfigure.orm.jpa.HibernateProperties.determinateHibernateproperties(HibernateProperties.java:91)~[spring-boot-autoconfigure-2.1.3.RELEASE.jar:2.1.3.RELEASE]
在org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration.getVendorProperties(HibernateJpaConfiguration.java:143)[spring-boot-autoconfigure-2.1.3.RELEASE.jar:2.1.3.RELEASE]
在org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.entityManagerFactory(JpaBaseConfiguration.java:139)~[spring-boot-autoconfigure-2.1.3.RELEASE.jar:2.1.3.RELEASE]
在org.springframework.boot.autoconfigure.orm.jpa.hibernatejpac配置$$EnhancerBySpringCGLIB$$d410246b.CGLIB$entityManagerFactory$8()~[spring-boot-autoconfigure-2.1.3.RELEASE.jar:2.1.3.RELEASE]
在org.springframework.boot.autoconfigure.orm.jpa.hibernatejpac配置$$EnhancerBySpringCGLIB$$d410246b$$FastClassBySpringCGLIB$$2772094c.invoke()~[spring-boot-autoconfigure-2.1.3.RELEASE.jar:2.1.3.RELEASE]
在org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)~[spring-core-5.1.5.RELEASE.jar:5.1.5.RELEASE]
在org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:363)~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
在org.springframework.boot.autoconfigure.orm.jpa.hibernatejpac配置$$EnhancerBySpringCGLIB$$d410246b.entityManagerFactory()~[spring-boot-autoconfigure-2.1.3.RELEASE.jar:2.1.3.RELEASE]
在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)~[na:1.8.0_112]
在sun.reflect.NativeMet
java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129) ~[mysql-connector-java-8.0.15.jar:8.0.15]
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) ~[mysql-connector-java-8.0.15.jar:8.0.15]
    at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) ~[mysql-connector-java-8.0.15.jar:8.0.15]
    at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:835) ~[mysql-connector-java-8.0.15.jar:8.0.15]
    at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:455) ~[mysql-connector-java-8.0.15.jar:8.0.15]
    at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240) ~[mysql-connector-java-8.0.15.jar:8.0.15]
    at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:199) ~[mysql-connector-java-8.0.15.jar:8.0.15]
    at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:136) ~[HikariCP-3.2.0.jar:na]
    at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:369) ~[HikariCP-3.2.0.jar:na]
    at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:198) ~[HikariCP-3.2.0.jar:na]
    at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:467) [HikariCP-3.2.0.jar:na]
    at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:541) [HikariCP-3.2.0.jar:na]
    at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115) [HikariCP-3.2.0.jar:na]
    at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112) [HikariCP-3.2.0.jar:na]
    at org.springframework.jdbc.datasource.DataSourceUtils.fetchConnection(DataSourceUtils.java:157) [spring-jdbc-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:115) [spring-jdbc-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:78) [spring-jdbc-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:324) [spring-jdbc-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.boot.jdbc.EmbeddedDatabaseConnection.isEmbedded(EmbeddedDatabaseConnection.java:123) [spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
    at org.springframework.boot.autoconfigure.orm.jpa.HibernateDefaultDdlAutoProvider.getDefaultDdlAuto(HibernateDefaultDdlAutoProvider.java:42) [spring-boot-autoconfigure-2.1.3.RELEASE.jar:2.1.3.RELEASE]
    at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration.lambda$getVendorProperties$1(HibernateJpaConfiguration.java:142) [spring-boot-autoconfigure-2.1.3.RELEASE.jar:2.1.3.RELEASE]
    at org.springframework.boot.autoconfigure.orm.jpa.HibernateSettings.getDdlAuto(HibernateSettings.java:41) ~[spring-boot-autoconfigure-2.1.3.RELEASE.jar:2.1.3.RELEASE]
    at org.springframework.boot.autoconfigure.orm.jpa.HibernateProperties.determineDdlAuto(HibernateProperties.java:130) ~[spring-boot-autoconfigure-2.1.3.RELEASE.jar:2.1.3.RELEASE]
    at org.springframework.boot.autoconfigure.orm.jpa.HibernateProperties.getAdditionalProperties(HibernateProperties.java:99) ~[spring-boot-autoconfigure-2.1.3.RELEASE.jar:2.1.3.RELEASE]
    at org.springframework.boot.autoconfigure.orm.jpa.HibernateProperties.determineHibernateProperties(HibernateProperties.java:91) ~[spring-boot-autoconfigure-2.1.3.RELEASE.jar:2.1.3.RELEASE]
    at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration.getVendorProperties(HibernateJpaConfiguration.java:143) [spring-boot-autoconfigure-2.1.3.RELEASE.jar:2.1.3.RELEASE]
    at org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.entityManagerFactory(JpaBaseConfiguration.java:139) ~[spring-boot-autoconfigure-2.1.3.RELEASE.jar:2.1.3.RELEASE]
    at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration$$EnhancerBySpringCGLIB$$d410246b.CGLIB$entityManagerFactory$8(<generated>) ~[spring-boot-autoconfigure-2.1.3.RELEASE.jar:2.1.3.RELEASE]
    at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration$$EnhancerBySpringCGLIB$$d410246b$$FastClassBySpringCGLIB$$2772094c.invoke(<generated>) ~[spring-boot-autoconfigure-2.1.3.RELEASE.jar:2.1.3.RELEASE]
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) ~[spring-core-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:363) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration$$EnhancerBySpringCGLIB$$d410246b.entityManagerFactory(<generated>) ~[spring-boot-autoconfigure-2.1.3.RELEASE.jar:2.1.3.RELEASE]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_112]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_112]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_112]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_112]
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:622) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:607) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1305) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1144) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1105) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) ~[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) ~[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) ~[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) ~[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) ~[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
    at com.example.demo.GroceryApplication.main(GroceryApplication.java:10) ~[classes/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_112]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_112]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_112]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_112]
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147) ~[idea_rt.jar:na]