第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Spring:如何將@RestClientTest 與帶有@Qualifier

Spring:如何將@RestClientTest 與帶有@Qualifier

蕭十郎 2022-10-07 17:32:00
我已經(jīng)更改了一個使用 a 的 Spring Boot (2.1.4) 服務RestTemplate來使用@Qualifier. 現(xiàn)在我的 Test (with @RestClientTestand @AutoConfigureWebClient) 失敗了,因為它無法解析 bean。我該如何解決?配置:  @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)}
查看完整描述

2 回答

?
當年話下

TA貢獻1890條經(jīng)驗 獲得超9個贊

您不應該使用(registerRestTemplate = true)它,因為它會為您創(chuàng)建一個不是您使用的 RestTemplate bean。

如果在您的 中聲明了您的合格 RestTemplate bean,請CastorConfiguration嘗試使用@Import(CastorConfiguration.class)


查看完整回答
反對 回復 2022-10-07
?
慕尼黑的夜晚無繁華

TA貢獻1864條經(jīng)驗 獲得超6個贊

對我有用的解決方案:(@AutoConfigureWebClient沒有(registerRestTemplate = true))。在@TestConfiguration類中創(chuàng)建一個RestTemplate具有權限的 bean@Qualifier


@Bean

@Qualifier("eureka")

public RestTemplate eurekaRestTemplate() {

  return new RestTemplate();

}

將其注入測試類


@Autowired

@Qualifier("eureka")

private RestTemplate restTemplate;

現(xiàn)在我們需要將它連接到MockRestServiceServer. 我們通過@BeforeEach


private MockRestServiceServer server;

@BeforeEach

  void setUp () {

    server = MockRestServiceServer.bindTo(restTemplate).build();

  }


查看完整回答
反對 回復 2022-10-07
  • 2 回答
  • 0 關注
  • 147 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號