I try to autowire feign client into the service, but the error is Could not autowire. No beans of 'OperatorClient' type found. Spring cloud version Finchley.SR2 Spring boot version 2.0.6.RELEASE
That is pom:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.spboot</groupId>
<artifactId>cloudexample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>cloudexample</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Finchley.SR2</spring-cloud.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</repository>
<repository>
<id>bintray-kptfh-feign-reactive</id>
<name>bintray</name>
<url>https://dl.bintray.com/kptfh/feign-reactive</url>
</repository>
</repositories>
</project>
That is main class:
@SpringBootApplication
@EnableFeignClients
@EnableDiscoveryClient
public class CloudExampleApplication {
public static void main(String[] args) {
SpringApplication.run(CloudExampleApplication.class, args);
}
}
FeignClient:
@FeignClient(name = "cloud-example")
public interface OperatorClient {
@RequestMapping(value = "/cloud-example/users", method = RequestMethod.GET)
String getUsers();
}
Controller:
@RestController
public class OperatorController {
@RequestMapping(value = "/users", method = RequestMethod.GET)
public String getUsers() {
return "Man";
}
}
Service:
@Data
@Service
public class CloudService {
@Autowired
private OperatorClient client;
public String getName() {
return client.getUsers();
}
}
Another Controller:
@RestController
@RequestMapping("/user")
public class UserController {
@Autowired
private CloudService service;
@GetMapping("/hello")
public String getUser() {
return "Hello " + service.getName() + "!";
}
}
So, in CloudService the OperatorClient isn't autowiring.
Comment From: ryanjbaxter
Can you provide a complete, minimal, verifiable sample that reproduces the problem? It should be available as a GitHub (or similar) project or attached to this issue as a zip file.
Comment From: alexciornii
@ryanjbaxter Sorry, but maybe i didn't put correctly the question. I try to autowire in project with version of spring boot 2.0.6.RELEASE and spring-cloud Finchley.SR2 feign client from project with version of spring boot 1.4.2.RELEASE and spring-cloud Camden.SR3. It's not autowiring! Spring Boot magic can't find feign clients from version below. Is any idea how can resolve it?
P.S. If it still need a sample, i will prepare it.
Comment From: ryanjbaxter
Yes please provide a sample
Comment From: alexciornii
- example of feign client consumer with version of spring boot 2.0.6.RELEASE and spring-cloud Finchley.SR2 https://github.com/alexciornii/cloud-example
- example of feign client consumer with version of spring boot 1.5.19.RELEASE and spring cloud Camden.SR3 https://github.com/alexciornii/feignconsumerexample
- example of feign client producer with version of spring boot 1.4.2.RELEASE Camden.SR3 https://github.com/alexciornii/feignexample
in project in p.1 can't autowiring feign client from project in p.3. But in project p.2 that's working fine. I think there was a conflict between versions. Is any way to autowiring feign client from below versions?
Comment From: spencergibb
Camden and Dalston are both end of life. Can you retry with Edgware?
Comment From: alexciornii
@spencergibb No. The same problem.
Comment From: ryanjbaxter
Please update your samples to use the latest Edgware or Finchley releases.
Comment From: alexciornii
@ryanjbaxter But i need it to be Camdem.
Comment From: spencergibb
Camden is no longer supported
Comment From: alexciornii
@spencergibb That's is understood. But if i have any project which is using Cadem.SR3 dependencies i can't use their feign clients in project with version above?
Comment From: ryanjbaxter
We are just not supporting Camden or Dalston any longer so if you can reproduce it with Edgeware than we can try and fix it there.
Comment From: alexciornii
@ryanjbaxter Reproduced with Edgware.SR5 https://github.com/alexciornii/feignexample https://github.com/alexciornii/cloud-example
Comment From: spencergibb
Unfortunately, you can't use an app with Finchley and import Edgware feign clients as the package of @FeignClient changed with the major release. They will all need to be Edgware or Finchley.
Comment From: alexciornii
Thanks.
Comment From: apostrophe
Make sure your import is correct: import org.springframework.cloud.openfeign.FeignClient;
NOT: import org.springframework.cloud.netflix.feign.FeignClient;
Comment From: leimbag
The same problem. And you can use @EnableFeignClients(basePackages = "com.xxx.xxx"), for scan feign client
Comment From: LiYeLin
add(require = false)after your @Autowired, that can solve the problem ,But it didn't address the root cause
Comment From: ankit5174
Same Problem when using Feign Client inside micronaut service. Does anyone has a workaround
Comment From: spencergibb
I doubt feign client works in micronaut.
Comment From: ankit5174
@spencergibb Do you know any reason why it cannot work in micronaut. According to my knowledge, micronaut uses Factory to create a instance of a external or dependency Bean(In in this eg CloudService). But DI wont allow OperatorClient to be injected since we are using new to create instance of CloudService. Let me know if my understanding is correct.
Comment From: spencergibb
I have no idea how micronaut implements anything spring. FeignClients are created using non-trivial proxy creation. Besides the error message, it's going to be totally unrelated to this issue.
Comment From: vieiralucas89
The same problem. And you can use @EnableFeignClients(basePackages = "com.xxx.xxx"), for scan feign client
Thank you, here working.
Comment From: jackDing2016
Make sure your import is correct: import org.springframework.cloud.openfeign.FeignClient;
NOT: import org.springframework.cloud.netflix.feign.FeignClient;
Thanks!
Comment From: theMentatHenrique
Hi, i resolve this problema using annotation @EnableFeignClients on applicationClass i follow this documentation : https://cloud.spring.io/spring-cloud-netflix/multi/multi_spring-cloud-feign.html