gpt4 book ai didi

dropwizard - 在 Dropwizard 中注册资源

转载 作者:行者123 更新时间:2023-12-02 20:19:17 26 4
gpt4 key购买 nike

我无法在 Dropwizard 应用程序的 run() 方法中注册多个资源。当我这样做时,我收到以下异常:

Exception in thread "main" MultiException[java.lang.IllegalArgumentException: A metric named io.dropwizard.db.ManagedPooledDataSource.postgresql.active already exists, java.util.concurrent.RejectedExecutionException: org.eclipse.jetty.util.thread.NonBlockingThread@27f74733]
at org.eclipse.jetty.server.Server.doStart(Server.java:329)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at io.dropwizard.cli.ServerCommand.run(ServerCommand.java:43)
at io.dropwizard.cli.EnvironmentCommand.run(EnvironmentCommand.java:43)
at io.dropwizard.cli.ConfiguredCommand.run(ConfiguredCommand.java:76)
at io.dropwizard.cli.Cli.run(Cli.java:70)
at io.dropwizard.Application.run(Application.java:73)
at com.xxx.xxx.yyy.GobblerHTTPApplication.main(GobblerHTTPApplication.java:19)

最佳答案

如果您碰巧使用 Hibernate 初始化数据库,例如。通过在主应用程序中使用以下代码段(两次):

private final HibernateBundle<Cfg> hib1 = new HibernateBundle<Cfg>(ImmutableList.of(SomeHibernateModel.class), new SessionFactoryFactory()) {
@Override
public DataSourceFactory getDataSourceFactory(Cfg configuration) {
return configuration.getDatabaseFactory();
}
};

那么覆盖另一个方法会很有帮助:“name()”方法。该方法是提供指标名称的最后一部分(“.postgresql.active”部分)的来源。像这样:

private final HibernateBundle<Cfg> hib1 = new HibernateBundle<Cfg>(ImmutableList.of(SomeHibernateModel.class), new SessionFactoryFactory()) {
@Override
public DataSourceFactory getDataSourceFactory(Cfg configuration) {
return configuration.getDatabaseFactory();
}
@Override
protected String name() {
return "hibernate.accesslog";
}

};

关于dropwizard - 在 Dropwizard 中注册资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29788929/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com