PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, November 4, 2022

[FIXED] Where is the parameter in this spring bean comming from

 November 04, 2022     circuit-breaker, java, lambda, spring-bean     No comments   

Issue

I am new to Spring and need to use the circuit breaker pattern, so I looked at the Spring Cloud Circuit Breaker project and saw this code

@Bean
public Customizer<Resilience4JCircuitBreakerFactory> defaultCustomizer() {
    return factory -> factory.configureDefault(id -> new Resilience4JConfigBuilder(id)
        .timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(4)).build())
        .circuitBreakerConfig(CircuitBreakerConfig.ofDefaults())
        .build());
 }

where is the factory coming from? is it injected?

The project where this code came from is here demo

cheers,

es


Solution

There is nothing injected.

The methods return a new instance of Customizer<Resilience4JCircuitBreakerFactory>

The code could also be written like this:

@Bean
public Customizer<Resilience4JCircuitBreakerFactory> defaultCustomizer() {
        return new Customizer<Resilience4JCircuitBreakerFactory>() {
            @Override
            public void customize(Resilience4JCircuitBreakerFactory factory) {
                factory.configureDefault(id -> new Resilience4JConfigBuilder(id)
                        .timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(3)).build())
                        .circuitBreakerConfig(CircuitBreakerConfig.ofDefaults())
                        .build());
            }
        };
    }

But because Customizer is a functional interface it can be written in a lambda.



Answered By - Simon Martinelli
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing