org.springframework.cloud.netflix.eureka.serviceregistry.EurekaServiceRegistry Java Examples

The following examples show how to use org.springframework.cloud.netflix.eureka.serviceregistry.EurekaServiceRegistry. 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: EurekaApplicationContextInitializer.java    From summerframework with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
    ConfigurableEnvironment environment = applicationContext.getEnvironment();
    applicationContext.getBeanFactory().addBeanPostProcessor(new InstantiationAwareBeanPostProcessorAdapter() {

        @Override
        public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
            if (bean instanceof CloudEurekaClient) {
                CloudEurekaClient eurekaClient = (CloudEurekaClient)bean;
                try {
                    Field filedPublisher = ReflectionUtils.findField(CloudEurekaClient.class, "publisher",
                        ApplicationEventPublisher.class);
                    ReflectionUtils.makeAccessible(filedPublisher);
                    ApplicationEventPublisher publisher =
                        (ApplicationEventPublisher)ReflectionUtils.getField(filedPublisher, eurekaClient);
                    return new EurekaClientWrapper(eurekaClient, environment, publisher);
                } finally {
                    Method method = ReflectionUtils.findMethod(CloudEurekaClient.class, "cancelScheduledTasks");
                    ReflectionUtils.makeAccessible(method);
                    ReflectionUtils.invokeMethod(method, eurekaClient);
                    eurekaClient = null;
                }
            } else if (bean instanceof EurekaServiceRegistry) {
                EurekaServiceRegistry eurekaServiceRegistry = (EurekaServiceRegistry)bean;
                return new EurekaServiceRegistryWrapper(eurekaServiceRegistry, environment);
            } else if (bean instanceof EurekaInstanceConfigBean) {
                EurekaInstanceConfigBean instanceConfig = (EurekaInstanceConfigBean)bean;
                instanceConfig.setPreferIpAddress(true);
                return bean;
            } else {
                return bean;
            }
        }
    });
}
 
Example #2
Source File: EurekaClientAutoConfiguration.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnBean(AutoServiceRegistrationProperties.class)
@ConditionalOnProperty(
		value = "spring.cloud.service-registry.auto-registration.enabled",
		matchIfMissing = true)
public EurekaAutoServiceRegistration eurekaAutoServiceRegistration(
		ApplicationContext context, EurekaServiceRegistry registry,
		EurekaRegistration registration) {
	return new EurekaAutoServiceRegistration(context, registry, registration);
}
 
Example #3
Source File: EurekaClientAutoConfigurationTests.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Test
public void eurekaConfigNotLoadedWhenDiscoveryClientDisabled() {
	TestPropertyValues.of("spring.cloud.discovery.enabled=false")
			.applyTo(this.context);
	setupContext(TestConfiguration.class);
	assertBeanNotPresent(EurekaClientConfigBean.class);
	assertBeanNotPresent(EurekaInstanceConfigBean.class);
	assertBeanNotPresent(DiscoveryClient.class);
	assertBeanNotPresent(EurekaServiceRegistry.class);
	assertBeanNotPresent(EurekaClient.class);
	assertBeanNotPresent(EurekaDiscoveryClientConfiguration.Marker.class);
}
 
Example #4
Source File: MossEurekaAutoServiceRegistration.java    From Moss with Apache License 2.0 4 votes vote down vote up
public MossEurekaAutoServiceRegistration(ApplicationContext context, EurekaServiceRegistry serviceRegistry, EurekaRegistration registration, EurekaRegistration registration1) {
    super(context, serviceRegistry, registration);
    this.registration = registration1;
}
 
Example #5
Source File: MultRegisterCenterServerMgmtConfig.java    From Moss with Apache License 2.0 4 votes vote down vote up
public EurekaServiceRegistry eurekaServiceRegistry() {
    return new EurekaServiceRegistry();
}
 
Example #6
Source File: MultRegisterCenterServerMgmtConfig.java    From Moss with Apache License 2.0 4 votes vote down vote up
public MossEurekaAutoServiceRegistration eurekaAutoServiceRegistration(ApplicationContext context, EurekaServiceRegistry registry,
                                                                       EurekaRegistration registration, EurekaRegistration registration1) {
    return new MossEurekaAutoServiceRegistration(context, registry, registration, registration1);
}
 
Example #7
Source File: EurekaInstanceDiscoveryClient.java    From spring-cloud-gray with Apache License 2.0 4 votes vote down vote up
@Override
public void afterPropertiesSet() throws Exception {
    eurekaServiceRegistry = applicationContext.getBean(EurekaServiceRegistry.class);
    eurekaRegistration = applicationContext.getBean(EurekaRegistration.class);
}
 
Example #8
Source File: EurekaClientAutoConfiguration.java    From spring-cloud-netflix with Apache License 2.0 4 votes vote down vote up
@Bean
public EurekaServiceRegistry eurekaServiceRegistry() {
	return new EurekaServiceRegistry();
}