2017-10-09 87 views
1

當我運行在AWS EC2實例的jar我的春天啓動的應用程序拋出錯誤。當我在本地系統中運行時,它工作正常。無法連接到MySQL在AWS

application.properties文件

spring.datasource.driver-class-name=com.mysql.jdbc.Driver 
spring.datasource.url=jdbc:mysql://localhost:3306/gbi? useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=fa lse&serverTimezone=UTC&autoReconnect=true&failOverReadOnly=false&maxReconne cts=10 
spring.jpa.database-platform =org.hibernate.dialect.MySQLDialect 
spring.datasource.username=****** 
spring.datasource.password=******@ 
spring.datasource.pool.size=20 
spring.jpa.hibernate.ddl-auto=update 
server.port=8090 

當我運行在AWS服務器的罐子,我收到以下錯誤

Unable to create initial connections of pool. 
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: 
Could not create connection to database server. Attempted reconnect 10 
times. Giving up. 
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 

其次,

Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: 
Communications link failure 

The last packet sent successfully to the server was 0 milliseconds ago. 
The driver has not received any packets from the server. 
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native 
Method) 
atsun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) 
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 

其次,

Caused by: java.net.ConnectException: Connection refused (Connection 
refused) 
at java.net.PlainSocketImpl.socketConnect(Native Method) 
atjava.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) 

其次,

2017-Oct-09 15:24:49.735 WARN [main] o.s.b.a.o.j.DatabaseLookup - 
Unable to determine jdbc url from datasource 
org.springframework.jdbc.support.MetaDataAccessException: Could not get 
Connection for extracting meta data; nested exception is 
org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get 
JDBC Connection; nested exception is 
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: 
Could not create connection to database server. Attempted reconnect 10 
times. Giving up. 

如何解決這個問題?

回答

0

得EC2和點擊安全組,然後在底部添加一個新的安全組類型MYSQL /極光protocal TCP和選擇的端口號,然後在源選擇您的計算機的IP地址。 你應該能夠解決您的問題。

謝謝, Madhu

+0

你是什麼意思「我的電腦的ip」?我應該把電腦的IP從我部署jar的地方? –

+0

我認爲這是在您的本地應用程序,所以我說把你的本地計算機的IP地址。如果不是,則創建一個安全組並將其添加到入站規則中 –