Всем здравствуйте! Пытаюсь обновить проект c Spring Boot 1.4.x на Spring Boot 2.0.6. Но после загрузки зависимостей и некоторых исправлений, не внедряются два FeignClient с других проектах. Пробовал создать простой пример используя Spring Boot 2.0.6 и зависимости Spring Cloud Finchley.SR2. В примере создал простой FeignClient и пытаюсь его внедрить через анотацию @Autowired, но не получается. Появляется ошибка о том что такой бин не найден. Обшарил куча примеров и документацию спринга но не получается никак решить данную проблему. Помогите кто в курсе.
Это контроллер:
@RequestMapping("/example")
@RestController
public class ExampleController {
@RequestMapping(value = "/users", method = RequestMethod.GET)
public String getUsers() {
return "users";
}
}
Это FeignClient:
@FeignClient("feign")
public interface ExampleClient {
@RequestMapping(value = "/feign/example/users", method = RequestMethod.GET)
String users();
}
Это сервис куда хочу внедрить клиент:
@Service
public class CloudService {
@Autowired
private ExampleClient client;
}
Получается что в сервис не внедряется клиент почему-то. Хотя пример делал по документации. Непонятно.
Это 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>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
<version>1.3.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<version>2.0.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-httpclient</artifactId>
</dependency>
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-jackson</artifactId>
<version>9.4.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</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>
<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>
<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>
</repositories>
</project>
И сам main class:
@SpringBootApplication
@EnableFeignClients
public class CloudexampleApplication {
public static void main(String[] args) {
SpringApplication.run(CloudexampleApplication.class, args);
}
}
@EnableFeignClients(basePackages = {"ExampleClient package"})
в CloudexampleApplicationpublic String getusers() { return client.users(); }
, в ExampleController добавил@Autowired CloudService cloudService;
. в маппинг прописал cloudService.getusers(); и все работает. точнее нет сообщения о том, что не может найти бина.