【发布时间】:2017-10-06 17:15:08
【问题描述】:
我有一个Spring Boot 应用程序连接到本地MySQL。我已经生成了jar 文件以将其上传到我的RaspberryPi 服务器上。 jar 文件已成功生成,但是当我将应用程序部署到我的服务器后尝试运行它时:
我看到了下面写的内容,但我想知道如何处理这个问题,因为当我在本地从 Intellij 运行它时,它可以正常启动?
对于您的问题,是的,我已经在服务器上安装了MySQL。
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_65]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_65]
Caused by: java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:964) ~[mysql-connector-java-5.1.40.jar!/:5.1.40]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3970) ~[mysql-connector-java-5.1.40.jar!/:5.1.40]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3906) ~[mysql-connector-java-5.1.40.jar!/:5.1.40]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:873) ~[mysql-connector-java-5.1.40.jar!/:5.1.40]
at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1710) ~[mysql-connector-java-5.1.40.jar!/:5.1.40]
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1226) ~[mysql-connector-java-5.1.40.jar!/:5.1.40]
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2253) ~[mysql-connector-java-5.1.40.jar!/:5.1.40]
at com.mysql.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:2104) ~[mysql-connector-java-5.1.40.jar!/:5.1.40]
... 58 common frames omitted
2017-05-08 17:45:21.543 WARN 29145 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
更新:-添加了application.properties
# LOCAL DATABASE
spring.datasource.url = jdbc:mysql://localhost:3306/test3?autoReconnect=true&useSSL=false
spring.datasource.username = root
spring.datasource.password = admin
# REMOTE DATABASE
#spring.datasource.url = jdbc:mysql://localhost:9090/test3
//in fact the address to the remote db is modraszka.sth.sth:8080
#spring.datasource.username = root
#spring.datasource.password = password
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
【问题讨论】:
标签: mysql spring spring-boot jar executable-jar