vinoth kumar
vinoth kumar

Reputation: 1

RibbonClient is not working. Field required a bean of type that could not be found

Error : Field proxy in com.project.currencyconversionservice.CurrencyConversionController required a bean of type 'com.project.currencyconversionservice.CurrencyExchangeServiceProxy' that could not be found.

Main file

@SpringBootApplication
@EnableFeignClients("com.project.currencyconversionservice")
public class CurrencyConversionServiceApplication {

    public static void main(String[] args) {
        SpringApplication.run(CurrencyConversionServiceApplication.class, args);
    }

}

CurrencyConversionController.java


@GetMapping("/currency-converter-feign/from/{from}/to/{to}/quantity/{quantity}")
    public CurrencyConversionBean converCurrencyFeign(
            @PathVariable String from, @PathVariable String to, @PathVariable BigDecimal quantity)
    {
        
        CurrencyConversionBean response = proxy.retrieveExchangeValue(from, to);
        return new CurrencyConversionBean(response.getId(),from,to,response.getConversionMultiple(),
                quantity,quantity.multiply(response.getConversionMultiple()),response.getPort());
        //return new CurrencyConversionBean(1L,from,to,BigDecimal.ONE,quantity,quantity,0);
    }

CurrencyExchangeServiceProxy.java

@FeignClient(name="currency-exchange-service")
@RibbonClient(name="currency-exchange-service")
public interface CurrencyExchangeServiceProxy {
    
    @GetMapping("currency-exchange/from/{from}/to/{to}")
    public CurrencyConversionBean retrieveExchangeValue(@PathVariable String from, @PathVariable String to);

}

application.properties

spring.application.name=currency-conversion-service
server.port=8100
currency-exchange-service.ribbon.listOfServers=http://localhost:8000,http://localhost:8001`your text`

CurrencyExchangeController.java

@Autowired
    private Environment environment;
    
    @Autowired
    private ExchangeValueRepository exchangeValueRepository;
    
    @GetMapping("currency-exchange/from/{from}/to/{to}")
    public ExchangeValue retrieveExchangeValue(@PathVariable String from, @PathVariable String to)
    {
        //ExchangeValue exchangeValue = new ExchangeValue(1000L, from, to, BigDecimal.valueOf(65));
        
        ExchangeValue exchangeValue = exchangeValueRepository.findByCfromAndCto(from,to);
        
        exchangeValue.setPort(Integer.parseInt(environment.getProperty("local.server.port")));
        return exchangeValue;
    }

Upvotes: 0

Views: 124

Answers (1)

vinoth kumar
vinoth kumar

Reputation: 1

I found the solution for above issue, Spring boot version 2.7.9 wont support Ribbon Loadbalancer, so i downgraded my spring boot version from 2.7.9 to 2.3.1.RELEASE.

Before pom.xml

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.9</version>
        <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>2021.0.6</spring-cloud.version>
    </properties>

<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
            <version>2.1.2.RELEASE</version>
</dependency>

After Changed my spring boot Version

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.1.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>Hoxton.SR5</spring-cloud.version>
    </properties>

<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
            <version>2.1.2.RELEASE</version>
        </dependency> 
        

Upvotes: 0

Related Questions