如何将beantalk应用程序连接到rds数据库

时间:2019-01-30 21:01:29

标签: amazon-web-services amazon-elastic-beanstalk

我正在尝试从部署在(AWS BeanStalk)上的Spring Web应用程序连接到RDS(AWS MySQL)。 检查日志后,我得到以下内容

Caused by: java.net.ConnectException: Connection refused (Connection refused)
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at com.mysql.cj.protocol.StandardSocketFactory.connect(StandardSocketFactory.java:155)
    at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:65)
    ... 20 more
java.lang.Exception: Query failed

Spring dataContext.xml

<bean id="mysqlDataSource"
    class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver" />
    <property name="url"
        value="jdbc:mysql://mydb.rds.amazonaws.com:3306" />
    <property name="username" value="user" />
    <property name="password" value="password" />
    <property name="validationQuery" value="SELECT 1" />
    <property name="testOnBorrow" value="true" />
</bean>

我还将BeanStalk安全组ID添加到RDS入站规则中,并且可以从本地PC访问RDS(添加了所有IP规则)。

1 个答案:

答案 0 :(得分:0)

我通过将EC2实例安全组添加到RDS入站规则并将RDS安全组添加到EC2实例配置中来使其工作