Why is the bean 'reactorServiceInstanceLoadBalancer' instantiated just when the method 'getInstance' is called?

pigman

Im trying to define a custom LoadBalancer by implementation the interface ReactorServiceInstanceLoadBalancer to replace the default load balancer defined by RoundRobinLoadBalancer.

But it doesn't work.

I found that the original bean defined in class 'LoadBalancerClientConfiguration' isn't instantiated when the application startup,but instantiated when 'LoadBalancerClientFactory.getInstance' is called, and the contructor is autowired with a bean of StandardEnvironment, while the bean defined in my configuration is instantiated when the application startup, and autowired with a bean of StandardReactiveWebEnvironment.

Very confused! My english is not so good.Thank you for reading the whole description! Here is my code below:

    `@Slf4j
public class CustomLoadBalancer implements ReactorServiceInstanceLoadBalancer {
    // ...detail omitted
}

@Configuration(proxyBeanMethods = false)
@ConditionalOnDiscoveryEnabled
public class CustomLoadBalancerClientConfiguration {
    @Bean
    public ReactorLoadBalancer<ServiceInstance> reactorServiceInstanceLoadBalancer(Environment environment, LoadBalancerClientFactory loadBalancerClientFactory, ServiceInstanceChooser serviceInstanceChooser) {
        String name = loadBalancerClientFactory.getName(environment);
        return new CustomLoadBalancer(serviceInstanceChooser, loadBalancerClientFactory.getLazyProvider(name, ServiceInstanceListSupplier.class), name);
    }
}
OlgaMaciaszek

A separate context, including the ReactorServiceInstanceLoadBalancer instance is created per requested serviceId. It is possible, to provide your own implementation, both default or for a specific service. Please see the documentation on how to provide custom configuration for Spring Cloud LoadBalancer.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

when is a spring bean instantiated

If DateFormat is an abstract class how is it instantiated with getInstance() method

@PostConstruct of bean instantiated class not getting called

When try call method every minute it called just twice

Spring AOP not working, when the method is called internally within a bean

Slot as method of a locally instantiated class is never called

why is mockito not called when executing mocked method?

Why is getParameterTypes empty when called on a controller Method?

XPages: why is my application bean instantiated twice?

Why is PartialView not called when being called from another ActionResult method?

Why custom callback not called when yield Request , but parse method called?

ngOnInit not being called when Injectable class is Instantiated

Method annotated with @Bean is called directly

Why should the getInstance() method in Factory pattern be static?

Why session bean method throw EjbTransactionRolledbackException when RuntimeException was thrown

Java - How to check if dynamically instantiated method is called at runtime?

Java: why equal method is not called when searching for same variable in hashmap

Why is BackingBean method called multiple times when requesting facelet?

Why will the compiler accept an invalid syntax call (<?>method) when statically called?

Why is this global list resetting to null when called by a GET Method?

Why is __get called instead of __call when I call a nonexistent method?

Why Ruby outputs [[:rest]] when the parameter method is called on String objects?

why object Destructor is not called when I come out of the method

Why is index method not called when action name is not specified

Why my Subscribe method is not called when using Prism EventAggregator?

flutter, Why not render ListView<Widget> when build method called?

Why is printstacktrace() of exception method does not print to console when ever called?

PHP 8.1.3 Why does a method call fail to start when called?

Why is it called "method hiding"?