2017-10-09 137 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地址。如果不是,则创建一个安全组并将其添加到入站规则中 –