Spring: Как объединить @RestClientTest с RestTemplate с @Qualifier?JAVA

Программисты JAVA общаются здесь
Ответить
Anonymous
 Spring: Как объединить @RestClientTest с RestTemplate с @Qualifier?

Сообщение Anonymous »

Я изменил службу Spring Boot (2.1.4), которая использует RestTemplate, чтобы использовать @Qualifier. Теперь мой тест (с @RestClientTest и @AutoConfigureWebClient) завершается неудачно, поскольку он не может разрешить компонент.

Как это исправить?

Конфигурация:

@Bean
@Qualifier("eureka")
@LoadBalanced
RestTemplate eurekaRestTemplate() {


Услуга:

public ClarkClient(
@Qualifier("eureka") RestTemplate restTemplate, ClarkConfiguration configuration)
throws URISyntaxException {


Тест:

@ExtendWith({SpringExtension.class, MockitoExtension.class})
@RestClientTest({CastorClient.class, CastorConfiguration.class})
@AutoConfigureWebClient(registerRestTemplate = true)
class CastorClientWebTest {

@Autowired
private CastorClient cut;

@Autowired
private MockRestServiceServer server;


Ошибка:

[2019-04-16T14:02:22,614] [WARN ] [ ....AnnotationConfigApplicationContext] [refresh 557] : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'castorClient' defined in file [/home/martinsc/java/routing/route-testing-batch-manager/out/production/classes/com/tyntec/routetesting/batchmanager/core/clients/CastorClient.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.web.client.RestTemplate' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Qualifier(value=eureka)}


Подробнее здесь: https://stackoverflow.com/questions/557 ... -qualifier
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»