Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
【メモ】Dropwizardで複数のデータベース(HibernateBundle)を使う ref: http://qiita.com/Kawata/items/872368226388204b02b3
package jp.hoge;
import java.util.HashMap;
import java.util.Map;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.dropwizard.Configuration;
import io.dropwizard.db.DataSourceFactory;
public class HogeConfiguration extends Configuration {
@Valid
@NotNull
@JsonProperty
private DataSourceFactory databaseHoge = new DataSourceFactory();
@Valid
@NotNull
@JsonProperty
private DataSourceFactory databaseFuga = new DataSourceFactory();
public DataSourceFactory getDatabaseHoge() {
return databaseHoge;
}
public DataSourceFactory getDatabaseFuga() {
return databaseFuga;
}
}
package jp.hoge;
import java.util.Map;
import io.dropwizard.Application;
import io.dropwizard.db.DataSourceFactory;
import io.dropwizard.hibernate.HibernateBundle;
import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;
public class HogeApplication extends Application<HogeConfiguration> {
public static void main(String[] args) throws Exception {
new HogeApplication().run(args);
}
@Override
public String getName() {
return "hogeapp";
}
private final HibernateBundle<HogeConfiguration> hogeHibernate = new HibernateBundle<HogeConfiguration>(AddressState.class,AddressCity.class,Station.class) {
// ここでnameを変えてあげないとエラーが出る
@Override
protected String name() {
return "hogeHibernate";
};
@Override
public DataSourceFactory getDataSourceFactory(HogeConfiguration configuration) {
return configuration.getDatabaseHoge();
}
};
private final HibernateBundle<HogeConfiguration> fugaHibernate = new HibernateBundle<HogeConfiguration>(Corporation.class, Job.class) {
// ここでnameを変えてあげないとエラーが出る
@Override
protected String name() {
return "fugaHibernate";
};
@Override
public DataSourceFactory getDataSourceFactory(HogeConfiguration configuration) {
return configuration.getDatabaseFuga();
}
};
@Override
public void initialize(Bootstrap<HogeConfiguration> bootstrap) {
bootstrap.addBundle(hogeHibernate);
bootstrap.addBundle(fugaHibernate);
}
@Override
public void run(HogeConfiguration config) {
}
}
WARN [2015-05-05 11:38:30,302] org.eclipse.jetty.util.component.AbstractLifeCycle: FAILED org.eclipse.jetty.server.ServerConnector$ServerConnectorManager@4
6046c06: java.util.concurrent.RejectedExecutionException: org.eclipse.jetty.util.thread.NonBlockingThread@4997552e
! java.util.concurrent.RejectedExecutionException: org.eclipse.jetty.util.thread.NonBlockingThread@4997552e
! at org.eclipse.jetty.util.thread.QueuedThreadPool.execute(QueuedThreadPool.java:362) ~[jetty-util-9.2.9.v20150224.jar:9.2.9.v20150224]
! at org.eclipse.jetty.io.SelectorManager.execute(SelectorManager.java:160) ~[jetty-io-9.2.9.v20150224.jar:9.2.9.v20150224]
! at org.eclipse.jetty.io.SelectorManager.doStart(SelectorManager.java:258) ~[jetty-io-9.2.9.v20150224.jar:9.2.9.v20150224]
! at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) [jetty-util-9.2.9.v20150224.jar:9.2.9.v20150224]
! at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132) [jetty-util-9.2.9.v20150224.jar:9.2.9.v20150224]
! at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:106) [jetty-util-9.2.9.v20150224.jar:9.2.9.v20150224]
! at org.eclipse.jetty.server.AbstractConnector.doStart(AbstractConnector.java:256) [jetty-server-9.2.9.v20150224.jar:9.2.9.v20150224]
! at org.eclipse.jetty.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:81) [jetty-server-9.2.9.v20150224.jar:9.2.9.v20150224]
! at org.eclipse.jetty.server.ServerConnector.doStart(ServerConnector.java:236) [jetty-server-9.2.9.v20150224.jar:9.2.9.v20150224]
! at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) [jetty-util-9.2.9.v20150224.jar:9.2.9.v20150224]
! at org.eclipse.jetty.server.Server.doStart(Server.java:366) [jetty-server-9.2.9.v20150224.jar:9.2.9.v20150224]
! at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) [jetty-util-9.2.9.v20150224.jar:9.2.9.v20150224]
! at io.dropwizard.cli.ServerCommand.run(ServerCommand.java:43) [dropwizard-core-0.8.1.jar:0.8.1]
! at io.dropwizard.cli.EnvironmentCommand.run(EnvironmentCommand.java:43) [dropwizard-core-0.8.1.jar:0.8.1]
! at io.dropwizard.cli.ConfiguredCommand.run(ConfiguredCommand.java:76) [dropwizard-core-0.8.1.jar:0.8.1]
! at io.dropwizard.cli.Cli.run(Cli.java:70) [dropwizard-core-0.8.1.jar:0.8.1]
! at io.dropwizard.Application.run(Application.java:73) [dropwizard-core-0.8.1.jar:0.8.1]
! at jp.hoge.HogeApplication.main(HogeApplication.java:22) [bin/:na]
WARN [2015-05-05 11:38:30,303] org.eclipse.jetty.util.component.AbstractLifeCycle: FAILED admin@54e12f4c{HTTP/1.1}{0.0.0.0:8081}: java.util.concurrent.Reje
ctedExecutionException: org.eclipse.jetty.util.thread.NonBlockingThread@4997552e
! java.util.concurrent.RejectedExecutionException: org.eclipse.jetty.util.thread.NonBlockingThread@4997552e
! at org.eclipse.jetty.util.thread.QueuedThreadPool.execute(QueuedThreadPool.java:362) ~[jetty-util-9.2.9.v20150224.jar:9.2.9.v20150224]
! at org.eclipse.jetty.io.SelectorManager.execute(SelectorManager.java:160) ~[jetty-io-9.2.9.v20150224.jar:9.2.9.v20150224]
! at org.eclipse.jetty.io.SelectorManager.doStart(SelectorManager.java:258) ~[jetty-io-9.2.9.v20150224.jar:9.2.9.v20150224]
! at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) [jetty-util-9.2.9.v20150224.jar:9.2.9.v20150224]
! at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132) ~[jetty-util-9.2.9.v20150224.jar:9.2.9.v20150224]
! at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:106) ~[jetty-util-9.2.9.v20150224.jar:9.2.9.v20150224]
! at org.eclipse.jetty.server.AbstractConnector.doStart(AbstractConnector.java:256) ~[jetty-server-9.2.9.v20150224.jar:9.2.9.v20150224]
! at org.eclipse.jetty.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:81) ~[jetty-server-9.2.9.v20150224.jar:9.2.9.v20150224]
! at org.eclipse.jetty.server.ServerConnector.doStart(ServerConnector.java:236) ~[jetty-server-9.2.9.v20150224.jar:9.2.9.v20150224]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.