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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

Mockito彈簧駱駝@Autowire失敗

Mockito彈簧駱駝@Autowire失敗

慕妹3146593 2021-04-27 09:46:55
我正在嘗試對(duì)駱駝路線進(jìn)行單元測(cè)試。被測(cè)試的路由擴(kuò)展了一個(gè)自定義的抽象RouteBuilder(我知道關(guān)于繼承優(yōu)先于繼承-這是維護(hù)代碼)。我已經(jīng)像@Roman Vottner在這里所做的那樣設(shè)置了測(cè)試。一切正常(初始化),直到我到達(dá)層次結(jié)構(gòu)中的第一個(gè)抽象類為止。它具有一個(gè)@Autowired類,即使在測(cè)試開始時(shí)對(duì)其進(jìn)行了模擬和@Autowired,該類也未初始化(為null)。關(guān)于如何解決注射問題的任何想法?@RunWith(CamelSpringRunner.class)@BootstrapWith(CamelTestContextBootstrapper.class)@ContextConfiguration(loader = AnnotationConfigContextLoader.class, classes = {FooRouteTest.ContextConfig.class})@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)public class FooRouteTest {  @Configuration  @PropertySource({"classpath:some.properties", "classpath:environment.properties"})  public static class ContextConfig extends CamelConfiguration {    @Bean    public UserServices userServices() {      return mock(UserServices.class);    } //and many more of the like  }  @Autowired  private UserServices userServices; //and all the others too  @Test  public void testAfoo() throws Exception {//....    template.setDefaultEndpointUri("direct://getTheData");    template.sendBody(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonNode));//...  }}在調(diào)試時(shí)在抽象超類中:@Autowiredpublic ClientServices clientServices;//...String clientNumber=clientServices.getLoggedInNumber();  //clientServices is null and not mocked!//...
查看完整描述

1 回答

?
楊__羊羊

TA貢獻(xiàn)1943條經(jīng)驗(yàn) 獲得超7個(gè)贊

通過將FooRoute顯式聲明為Bean來解決此問題:


@Bean

public FooRoute fooRoute(){

  return new FooRoute();

}


@Override

public List<RouteBuilder> routes() {

  final List<RouteBuilder> routes = new ArrayList<>();

  routes.add(fooRoute());

  return routes;

}

http://img1.sycdn.imooc.com//609b33720001f80f09040903.jpg

查看完整回答
反對(duì) 回復(fù) 2021-05-12
  • 1 回答
  • 0 關(guān)注
  • 189 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)