io.dropwizard.configuration.ConfigurationValidationException

io.dropwizard.configuration.ConfigurationValidationException

我是 dropwizard/eclipse 的新手,正在关注 Example code

我在 JDK 8 中使用 Eclipse 2018-12,在尝试 运行 java 应用程序时出现以下错误

io.dropwizard.configuration.ConfigurationValidationException: default configuration has the following errors: * apiKey may not be empty * apiURL may not be empty

at io.dropwizard.configuration.BaseConfigurationFactory.validate(BaseConfigurationFactory.java:238)
at io.dropwizard.configuration.BaseConfigurationFactory.build(BaseConfigurationFactory.java:128)
at io.dropwizard.configuration.BaseConfigurationFactory.build(BaseConfigurationFactory.java:109)
at io.dropwizard.cli.ConfiguredCommand.parseConfiguration(ConfiguredCommand.java:128)
at io.dropwizard.cli.ConfiguredCommand.run(ConfiguredCommand.java:74)
at io.dropwizard.cli.Cli.run(Cli.java:78)
at io.dropwizard.Application.run(Application.java:93)
at com.recheck.helloRecheck.HelloRecheckApplication.main(HelloRecheckApplication.java:18)

我的config.yml文件如下

apiURL: https://openexchangerates.org/api/latest.json
apiKey: 307738b2b3164072b4bfdc2828dd5f33

jerseyClient: 
timeout: 512ms
workQueueSize: 16 

我的申请文件如下

public class HelloRecheckApplication extends Application<HelloRecheckConfiguration> {

public static void main(final String[] args) throws Exception {
    new HelloRecheckApplication().run(args);
}

@Override
public String getName() {
    return "HelloRecheck";
}

//@Override
public void initialize(final Bootstrap<HelloRecheckConfiguration> bootstrap) {
    // TODO: application initialization
}

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

    //Create Jersey client.
    final Client client = new JerseyClientBuilder(environment)
            .using(configuration.getJerseyClientConfiguration())
            .build(getName());

    environment.jersey().register(new HelloResource());
    //Register a resource using Jersey client.
    environment.jersey().register(
            new ConverterResource(
                    client,
                    configuration.getApiURL(),
                    configuration.getApiKey())
            );


}

}

我的 Pom 文件如下所示

    <modelVersion>4.0.0</modelVersion>
<prerequisites>
    <maven>3.0.0</maven>
</prerequisites>

<groupId>com.recheck</groupId>
<artifactId>helloRecheck</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>HelloRecheck</name>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <dropwizard.version>1.3.8</dropwizard.version>
    <mainClass>com.recheck.helloRecheck.HelloRecheckApplication</mainClass>
</properties>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>io.dropwizard</groupId>
            <artifactId>dropwizard-bom</artifactId>
            <version>${dropwizard.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <dependency>
        <groupId>io.dropwizard</groupId>
        <artifactId>dropwizard-core</artifactId>
    </dependency>
    <dependency>
        <groupId>io.dropwizard</groupId>
        <artifactId>dropwizard-auth</artifactId>
    </dependency>
    <dependency>
        <groupId>io.dropwizard</groupId>
        <artifactId>dropwizard-hibernate</artifactId>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.36</version>
    </dependency>
    <dependency>
        <groupId>io.dropwizard</groupId>
        <artifactId>dropwizard-client</artifactId>
    </dependency>
    <dependency>
        <groupId>io.dropwizard</groupId>
        <artifactId>dropwizard-testing</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.4.1</version>
            <configuration>
                <createDependencyReducedPom>true</createDependencyReducedPom>
                <transformers>
                    <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                    <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                        <mainClass>${mainClass}</mainClass>
                    </transformer>
                </transformers>

有人可以指导我应该检查什么来解决这个问题。

我想通了。 需要在参数中添加 config.yml。