com.hubspot.dropwizard.guice.GuiceBundle Java Examples

The following examples show how to use com.hubspot.dropwizard.guice.GuiceBundle. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DropwizardService.java    From katharsis-framework with Apache License 2.0 6 votes vote down vote up
@Override
public void initialize(Bootstrap<DropwizardConfiguration> bootstrap) {

    guiceBundle = GuiceBundle.<DropwizardConfiguration>newBuilder()
            .addModule(new AbstractModule() {

                @Override
                protected void configure() {
                    bind(ProjectRepository.class);
                    bind(TaskRepository.class);
                    bind(TaskToProjectRepository.class);
                }

                @Provides
                public MongoManaged mongoManaged(DropwizardConfiguration configuration) throws Exception {
                    return new MongoManaged(configuration.mongo);
                }
            })
            .setConfigClass(DropwizardConfiguration.class)
            .build();

    bootstrap.addBundle(guiceBundle);
}
 
Example #2
Source File: ServerApplication.java    From eagle with Apache License 2.0 6 votes vote down vote up
@Override
public void initialize(Bootstrap<ServerConfig> bootstrap) {
    LOG.debug("Loading and registering guice bundle");
    GuiceBundle<ServerConfig> guiceBundle = GuiceBundleLoader.load();
    bootstrap.addBundle(guiceBundle);

    LOG.debug("Loading and registering static AssetsBundle on /assets");
    bootstrap.addBundle(new AssetsBundle("/assets", "/", "index.html", "/"));

    LOG.debug("Initializing guice injector context for current ServerApplication");
    guiceBundle.getInjector().injectMembers(this);

    try {
        EntityRepositoryScanner.scan();
    } catch (IllegalAccessException | InstantiationException e) {
        LOG.error("Failed to scan entity repository", e);
    }
}
 
Example #3
Source File: DropwizardApplication.java    From microservices-comparison with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(Bootstrap<DropwizardServerConfiguration> bootstrap) {
    guiceBundle = GuiceBundle.<DropwizardServerConfiguration>newBuilder()
            .addModule(new HelloModule())
            .addModule(new CarModule())
            .setConfigClass(DropwizardServerConfiguration.class)
            .build();
    bootstrap.addBundle(guiceBundle);
    bootstrap.addBundle(new Java8Bundle());

    ObjectMapper objectMapper = bootstrap.getObjectMapper();
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}
 
Example #4
Source File: SimulatorService.java    From tr069-simulator with MIT License 5 votes vote down vote up
@Override
public void initialize(Bootstrap<SimulatorConfiguration> bootstrap) {
	bootstrap.setName("TR069-Simulator");
	bootstrap.addBundle(new ConfiguredAssetsBundle("/assets/", "/dashboard/") );
	bootstrap.addBundle(new ViewBundle());
	bootstrap.addBundle(GuiceBundle.newBuilder()
			.addModule(new SimulatorModule())
			.enableAutoConfig(getClass().getPackage().getName())
			.build()
			);


}
 
Example #5
Source File: GuiceBundleLoader.java    From eagle with Apache License 2.0 4 votes vote down vote up
public static GuiceBundle<ServerConfig> load(List<Module> modules) {
    /*
       We use tow injectors, one is Dropwizard injector, the other injector is to instantiate ApplicationProvider and
       load sub modules from applications
       so we need make Config and ApplicationProviderServiceImpl to have a global instance across multiple injectors
     */

    // Eagle server module
    Config config = ConfigFactory.load();
    ApplicationProviderService appProviderSvc = new ApplicationProviderServiceImpl(config);
    ServerModule serveBaseModule = new ServerModule(appProviderSvc);

    // load application specific modules
    ModuleRegistry registry = ApplicationExtensionLoader.load(serveBaseModule);

    // add application specific modules
    MetadataStore metadataStoreModule = MetadataStoreModuleFactory.getModule();
    List<Module> metadataExtensions = metadataStoreModule.getModules(registry);
    int extensionNum = 0;
    GuiceBundle.Builder<ServerConfig> builder = GuiceBundle.newBuilder();
    if (metadataExtensions != null) {
        extensionNum = metadataExtensions.size();
        metadataExtensions.forEach(builder::addModule);
    }
    LOGGER.warn("Loaded {} modules (scope: metadataStore)", extensionNum);

    List<Module> globalExtensions = registry.getModules(GlobalScope.class);
    extensionNum = 0;
    if (globalExtensions != null) {
        extensionNum = globalExtensions.size();
        globalExtensions.forEach(builder::addModule);
    }
    LOGGER.warn("Loaded {} modules (scope: global)", extensionNum);

    if (modules != null) {
        modules.forEach(builder::addModule);
    }
    return builder.addModule(serveBaseModule)
        .setConfigClass(ServerConfig.class)
        .build();
}
 
Example #6
Source File: GuiceBundleLoader.java    From eagle with Apache License 2.0 4 votes vote down vote up
public static GuiceBundle<ServerConfig> load() {
    return load(null);
}
 
Example #7
Source File: GuiceBundleLoaderTest.java    From eagle with Apache License 2.0 4 votes vote down vote up
@Test
public void testLoad() {
    GuiceBundle<ServerConfig> bundle = GuiceBundleLoader.load();
}