部署在服务器上的SpringBoot应用程序不希望与DB连接

时间:2017-05-08 15:53:59

标签: mysql spring spring-boot jar executable-jar

我有一个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

1 个答案:

答案 0 :(得分:0)

Makevsure你的凭据很好,mysql作为服务运行。你可以在services.msc中查看它。你可以共享你的application.properties文件吗?