为什么我无法使用 Dropwizard 连接到 AWS RDS 实例?

Why Can't I connect to AWS RDS instance with Dropwizard?

我现在有一个简单的 Dropwizard API,它有一个端点到 return 我的 AWS RDS 数据库中的所有用户,还有一个 "hello world" 端点。我可以在我的开发机器上使用 MySQL Workbench 连接到我的 RDS 实例,所以我知道连接是允许的。

我的应用程序已构建,最初 运行 没问题。我有一个正在工作的 "hello world" 端点,但是当我尝试点击我的 /users/all 端点时,出现以下错误:

ERROR [2016-05-01 23:47:07,305] io.dropwizard.jersey.errors.LoggingExceptionMapper: Error handling a request: b92c1a9ace3378bf
! java.sql.SQLException: No database selected
! at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074)
! at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4096)
! at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4028)
! at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2490)
! at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2651)
! at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2734)
! at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)
! at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1379)
! at org.skife.jdbi.v2.SQLStatement.internalExecute(SQLStatement.java:1327)
! ... 66 common frames omitted

我相信我正在使用来自 Sonatype Nexus Snapshots1.0.0-rc3-SNAPSHOT Dropwizard 版本。

在我的 config.yml 中,我有:

database:
  driverClass: com.mysql.jdbc.Driver
  user: <my_user>
  password: <my_password>
  url: jdbc:mysql://<my_db>.blah.rds.amazonaws.com

我的配置class很简单,仅限于以下

public class AppConfiguration extends Configuration {

    @Valid
    @NotNull
    private DataSourceFactory database = new DataSourceFactory();

    @JsonProperty("database")
    public DataSourceFactory getDataSourceFactory() {
        return database;
    }

}

我的服务 运行 方法如下所示:

@Override
public void run(AppConfiguration configuration, Environment environment) {

    environment.jersey().register(RolesAllowedDynamicFeature.class);
    environment.jersey().register(new AppResource());

    /* initialize DB and DAOs */
    final DBIFactory factory = new DBIFactory();
    final DBI jdbi = factory.build(environment, configuration.getDataSourceFactory(), "mysql");

    final UserDAO userDAO = jdbi.onDemand(UserDAO.class);

    /* Initialize Resources */
    final UserResource userResource = new UserResource(userDAO);
    environment.jersey().register(userResource);

}

我尝试在 运行ning 期间调试应用程序,发现我的 userDAO 对象已创建。我尝试深入研究实例 variables/functions,但找不到任何有用的信息来解释它未连接的原因。

您没有在 JDBC URL 中正确指定数据库。查看指定的格式herejdbc:mysql://[host1][:port1][,[host2][:port2]]...[/[database]]