Skip to content

Instantly share code, notes, and snippets.

@john-nash-rs
Last active July 12, 2018 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save john-nash-rs/eb523c16e439ec0012ad11989276a02a to your computer and use it in GitHub Desktop.
Save john-nash-rs/eb523c16e439ec0012ad11989276a02a to your computer and use it in GitHub Desktop.
import io.dropwizard.Application;
import io.dropwizard.db.DataSourceFactory;
import io.dropwizard.hibernate.HibernateBundle;
import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;
/**
* Created by harshvardhan on 12/07/18.
*/
public class MyApplication extends Application<MyConfiguration> {
public static void main(String[] args) throws Exception {
new MyApplication().run(args);
}
public void run(MyConfiguration myConfiguration, Environment environment) throws Exception {
System.out.println("Value from dev.yml is "+myConfiguration.getDataSourceFactory().getUser());
InfoDao infoDao = new InfoDao(hibernate.getSessionFactory());
final MyResource resource = new MyResource(infoDao);
environment.jersey().register(resource);
}
private HibernateBundle<MyConfiguration> hibernate = new HibernateBundle<MyConfiguration>(Info.class) {
@Override
public DataSourceFactory getDataSourceFactory(MyConfiguration configuration) {
return configuration.getDataSourceFactory();
}
};
@Override
public String getName() {
return "dropwizard-hibernate";
}
@Override
public void initialize(Bootstrap<MyConfiguration> bootstrap) {
bootstrap.addBundle(hibernate);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment