use of com.netflix.governator.LifecycleInjector in project eureka by Netflix.
the class EurekaClientModuleConfigurationTest method testBindEurekaInstanceConfigFactory.
@Test
public void testBindEurekaInstanceConfigFactory() {
final EurekaInstanceConfigFactory mockFactory = Mockito.mock(EurekaInstanceConfigFactory.class);
final EurekaInstanceConfig mockConfig = Mockito.mock(EurekaInstanceConfig.class);
final ApplicationInfoManager mockInfoManager = Mockito.mock(ApplicationInfoManager.class);
Mockito.when(mockFactory.get()).thenReturn(mockConfig);
LifecycleInjector injector = InjectorBuilder.fromModules(new ArchaiusModule(), new EurekaClientModule() {
@Override
protected void configureEureka() {
bindEurekaInstanceConfigFactory().toInstance(mockFactory);
}
}).overrideWith(new AbstractModule() {
@Override
protected void configure() {
// this is usually bound as an eager singleton that can trigger other parts to
// initialize, so do an override to a mock here to prevent that.
bind(ApplicationInfoManager.class).toInstance(mockInfoManager);
}
}).createInjector();
EurekaInstanceConfig config = injector.getInstance(EurekaInstanceConfig.class);
Assert.assertEquals(mockConfig, config);
}
use of com.netflix.governator.LifecycleInjector in project eureka by Netflix.
the class ExampleEurekaGovernatedService method init.
private static LifecycleInjector init() throws Exception {
System.out.println("Creating injector for Example Service");
LifecycleInjector injector = InjectorBuilder.fromModules(new EurekaModule(), new ExampleServiceModule()).overrideWith(new AbstractModule() {
@Override
protected void configure() {
DynamicPropertyFactory configInstance = com.netflix.config.DynamicPropertyFactory.getInstance();
bind(DynamicPropertyFactory.class).toInstance(configInstance);
// the default impl of EurekaInstanceConfig is CloudInstanceConfig, which we only want in an AWS
// environment. Here we override that by binding MyDataCenterInstanceConfig to EurekaInstanceConfig.
bind(EurekaInstanceConfig.class).to(MyDataCenterInstanceConfig.class);
// (DiscoveryClient optional bindings) bind the optional event bus
// bind(EventBus.class).to(EventBusImpl.class).in(Scopes.SINGLETON);
}
}).createInjector();
System.out.println("Done creating the injector");
return injector;
}
use of com.netflix.governator.LifecycleInjector in project eureka by Netflix.
the class ExampleEurekaGovernatedService method main.
public static void main(String[] args) throws Exception {
LifecycleInjector injector = null;
try {
injector = init();
injector.awaitTermination();
} catch (Exception e) {
System.out.println("Error starting the sample service: " + e);
e.printStackTrace();
} finally {
if (injector != null) {
injector.shutdown();
}
}
}
use of com.netflix.governator.LifecycleInjector in project eureka by Netflix.
the class EurekaContextListener method createInjector.
@Override
protected LifecycleInjector createInjector() {
// For backward compatibility
JsonXStream.getInstance().registerConverter(new V1AwareInstanceInfoConverter(), XStream.PRIORITY_VERY_HIGH);
XmlXStream.getInstance().registerConverter(new V1AwareInstanceInfoConverter(), XStream.PRIORITY_VERY_HIGH);
LifecycleInjector injector = EurekaInjectorCreator.createInjector();
serverContext = injector.getInstance(EurekaServerContext.class);
return injector;
}
Aggregations