Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Consider defining a bean of type 'org.springframework.cloud.openfeign.FeignContext' in your configuration

I am trying to run the application but this error keeps prompting.

Description:

Parameter 0 of constructor in com.clientui.clientui.controller.ClientController required a bean of type 'org.springframework.cloud.openfeign.FeignContext' that could not be found.

Action:

Consider defining a bean of type 'org.springframework.cloud.openfeign.FeignContext' in your configuration.

Here is the code:

Main

    package com.clientui.clientui;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@SpringBootApplication
@EnableFeignClients("com.clientui")

public class ClientuiApplication {

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

}

Controller

package com.clientui.clientui.controller;

import com.clientui.clientui.beans.ProductBean;
import com.clientui.clientui.proxies.MicroserviceProduitsProxy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class ClientController {

    private final MicroserviceProduitsProxy produitsProxy;

    public ClientController(MicroserviceProduitsProxy produitsProxy){
        this.produitsProxy = produitsProxy;
    }

    @RequestMapping("/")
    public String accueil(Model model){
        List<ProductBean> produits =  produitsProxy.listeDesProduits();
        model.addAttribute("produits", produits);
        return "Accueil";
    }
}
like image 227
mikasa acker Avatar asked Jan 19 '26 19:01

mikasa acker


2 Answers

I had the same problem when updating the spring-boot version to 3.0.0, I think it's some compatibility bug with spring cloud and spring boot's autoconfigure. I solved it by adding the annotation @ImportAutoConfiguration({FeignAutoConfiguration.class}) in the application, in your case:

import org.springframework.cloud.openfeign.FeignAutoConfiguration;

@SpringBootApplication
@EnableFeignClients("com.clientui")
@ImportAutoConfiguration({FeignAutoConfiguration.class})
public class ClientuiApplication {

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

}
like image 55
Joaonic Avatar answered Jan 22 '26 15:01

Joaonic


I use Spring Boot 3.0.0 and faced the same issue and resolved it by using 2022.0.0-RC2 version of spring-cloud-dependencies. (https://docs.spring.io/spring-cloud/docs/2022.0.0-RC2/reference/html/). It should work with Spring Boot 3.0.0.

If you are using Maven add this to your dependencyManagement section in pom.xml:

<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-dependencies</artifactId>
  <version>2022.0.0-RC2</version>
  <type>pom</type>
  <scope>import</scope>
</dependency>

Note: For the time I am writing this answer 2022.0.0-RC2 version is not available in central repository but you can find it in Spring Lib M repository so you should also add it to your repositories section in pom.xml:

<repository>
  <id>lib-m</id>
  <name>Spring Lib M</name>
  <url>https://repo.spring.io/libs-milestone/</url>
</repository>
like image 29
Олег Шилюк Avatar answered Jan 22 '26 16:01

Олег Шилюк



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!