Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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

Ask Question

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:

    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";

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);

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>
import org.springframework.cloud.openfeign.FeignAutoConfiguration;
@ImportAutoConfiguration({FeignAutoConfiguration.class})

Adding these line on main app fixes the issue.

If you are using Spring 3.0.0 the "spring.factories" has been removed. The automatic import of autoconfigurations is broken if your dependency uses this.

https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.0-Migration-Guide#auto-configuration-files

The one way to fix this on your side without modifying the dependecy itself is using @ImportAutoConfiguration({ list of autoconfiguration classes }) explicitly. You can also use new functionality "imports file" provided by Spring. The right way is to migrate "spring.factories" to "imports file" on the dependency side.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.