【发布时间】:2016-12-11 17:26:02
【问题描述】:
我希望在不引导整个 Dropwizard 服务器的情况下测试 Dropwizard 的“应用程序”类。
我基本上只是想确保我正在注册的一个捆绑包已成功注册。
到目前为止,我遇到的所有路由都导致 NullPointer 异常,因为其他各种组件没有正确设置。这里有一条简单的路吗?
public class SentimentApplication extends Application<SentimentConfiguration> {
public static void main(final String[] args) throws Exception {
new SentimentApplication().run(args);
}
@Override
public String getName() {
return "Sentiment";
}
@Override
public void initialize(final Bootstrap<SentimentConfiguration> bootstrap) {
bootstrap.setConfigurationSourceProvider(
new SubstitutingSourceProvider(bootstrap.getConfigurationSourceProvider(),
new EnvironmentVariableSubstitutor(false)
)
);
}
@Override
public void run(final SentimentConfiguration configuration,
final Environment environment) {
// TODO: implement application
}
}
【问题讨论】:
-
什么代码会产生 NPE,请您也分享一下堆栈跟踪。
标签: java dropwizard