久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  • <i id='HaPbh'><tr id='HaPbh'><dt id='HaPbh'><q id='HaPbh'><span id='HaPbh'><b id='HaPbh'><form id='HaPbh'><ins id='HaPbh'></ins><ul id='HaPbh'></ul><sub id='HaPbh'></sub></form><legend id='HaPbh'></legend><bdo id='HaPbh'><pre id='HaPbh'><center id='HaPbh'></center></pre></bdo></b><th id='HaPbh'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='HaPbh'><tfoot id='HaPbh'></tfoot><dl id='HaPbh'><fieldset id='HaPbh'></fieldset></dl></div>

    <small id='HaPbh'></small><noframes id='HaPbh'>

    <legend id='HaPbh'><style id='HaPbh'><dir id='HaPbh'><q id='HaPbh'></q></dir></style></legend>

      1. <tfoot id='HaPbh'></tfoot>

          <bdo id='HaPbh'></bdo><ul id='HaPbh'></ul>
      2. Mockito + Spring + @PostConstruct,mock初始化錯誤,為什

        Mockito + Spring + @PostConstruct, mock initialization error, why is @PostConstruct called?(Mockito + Spring + @PostConstruct,mock初始化錯誤,為什么會調用@PostConstruct?)

            <bdo id='sBMKu'></bdo><ul id='sBMKu'></ul>
            <legend id='sBMKu'><style id='sBMKu'><dir id='sBMKu'><q id='sBMKu'></q></dir></style></legend>

              <small id='sBMKu'></small><noframes id='sBMKu'>

                  <tbody id='sBMKu'></tbody>
                <i id='sBMKu'><tr id='sBMKu'><dt id='sBMKu'><q id='sBMKu'><span id='sBMKu'><b id='sBMKu'><form id='sBMKu'><ins id='sBMKu'></ins><ul id='sBMKu'></ul><sub id='sBMKu'></sub></form><legend id='sBMKu'></legend><bdo id='sBMKu'><pre id='sBMKu'><center id='sBMKu'></center></pre></bdo></b><th id='sBMKu'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='sBMKu'><tfoot id='sBMKu'></tfoot><dl id='sBMKu'><fieldset id='sBMKu'></fieldset></dl></div>
                1. <tfoot id='sBMKu'></tfoot>
                2. 本文介紹了Mockito + Spring + @PostConstruct,mock初始化錯誤,為什么會調用@PostConstruct?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我有這樣的設置:

                  Bean類:

                  private final Map<String, String> configCache = new HashMap<>();
                  @PostConstruct
                  private void fillCache() {  (...) configCache.clear();} 
                  

                  TestConfig 類:

                  @Bean
                  @Order(Ordered.HIGHEST_PRECEDENCE)
                  @Primary
                  public Bean beanMock() {
                      return Mockito.mock(Bean.class);
                  }
                  

                  Test 類:哪個 @Autowires bean.

                  Test class: which @Autowires the bean.

                  似乎當 Mockito 在 TestConfig 中創建模擬時,它調用了 @PostConstruct ,而 @PostConstruct 又似乎在映射字段初始化之前被調用,因此它引發了異常.

                  It seems when Mockito is creating the mock in TestConfig, it calls @PostConstruct which in turn seems to be called before the map field is initialized so it throws an exception.

                  我的問題是:

                  • 為什么 Mockito 調用 @PostConstruct?
                  • 如何禁用 @PostConstruct 進行模擬?

                  顯然調用是在 Spring 從 Config 的 @Bean 方法中重新調用 bean 之前的實例化之后完成的

                  Apparently the call is done after the instantiation just before Spring retrns the bean from a Config's @Bean method

                  推薦答案

                  Mockito 沒有調用 @PostConstruct -- Spring 是.你說在你的測試中你使用了 @Autowired,這不是一個 Mockito 注釋.

                  Mockito isn't calling @PostConstruct -- Spring is. You say that in your test you use @Autowired, which is not a Mockito annotation.

                  如果您打算使用 @Mock,您會發現 Mockito 不會調用您的 @PostConstruct 方法.

                  If you meant to use @Mock, you'll find that Mockito won't call your @PostConstruct method.

                  換句話說,像這樣編寫你的測試類:

                  In other words, write your test class like this:

                  @Mock Bean myBean;
                  
                  @Before
                  public void before() {
                      MockitoAnnotations.initMocks();
                  }
                  

                  這篇關于Mockito + Spring + @PostConstruct,mock初始化錯誤,為什么會調用@PostConstruct?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  How can I detect integer overflow on 32 bits int?(如何檢測 32 位 int 上的整數溢出?)
                  Local variables before return statements, does it matter?(return 語句之前的局部變量,這有關系嗎?)
                  How to convert Integer to int?(如何將整數轉換為整數?)
                  How do I create an int array with randomly shuffled numbers in a given range(如何在給定范圍內創建一個隨機打亂數字的 int 數組)
                  Inconsistent behavior on java#39;s ==(java的行為不一致==)
                  Why is Java able to store 0xff000000 as an int?(為什么 Java 能夠將 0xff000000 存儲為 int?)

                      • <bdo id='PkfUg'></bdo><ul id='PkfUg'></ul>
                          <tbody id='PkfUg'></tbody>

                        <small id='PkfUg'></small><noframes id='PkfUg'>

                        <i id='PkfUg'><tr id='PkfUg'><dt id='PkfUg'><q id='PkfUg'><span id='PkfUg'><b id='PkfUg'><form id='PkfUg'><ins id='PkfUg'></ins><ul id='PkfUg'></ul><sub id='PkfUg'></sub></form><legend id='PkfUg'></legend><bdo id='PkfUg'><pre id='PkfUg'><center id='PkfUg'></center></pre></bdo></b><th id='PkfUg'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='PkfUg'><tfoot id='PkfUg'></tfoot><dl id='PkfUg'><fieldset id='PkfUg'></fieldset></dl></div>
                        <tfoot id='PkfUg'></tfoot>

                        • <legend id='PkfUg'><style id='PkfUg'><dir id='PkfUg'><q id='PkfUg'></q></dir></style></legend>

                            主站蜘蛛池模板: av黄色免费 | 精品国产乱码久久久久久丨区2区 | 中文字幕高清 | 国产精品久久久久999 | 视频一区二区在线观看 | 九色在线| 欧美日韩亚洲国产 | 亚洲乱码国产乱码精品精98午夜 | 亚洲精品一区二区三区蜜桃久 | 国产综合精品一区二区三区 | 日本黄色的视频 | 亚洲精彩视频在线观看 | 日韩欧美视频在线 | 高清av电影 | 国产成人精品在线 | 成人av网站在线观看 | 爱综合 | 久久青 | www.久久.com | 最新超碰 | 日韩一区二区免费视频 | 精品国产鲁一鲁一区二区张丽 | 免费视频一区二区三区在线观看 | 久久国产精品首页 | 久久精品黄色 | 精品一区二区久久久久久久网精 | 日韩超碰 | 四虎在线观看 | 一区二区三区欧美在线 | 午夜电影网站 | 欧美精品在线播放 | 精品国产三级 | 美女视频网站久久 | 国产欧美一区二区三区国产幕精品 | 在线视频亚洲 | 国产综合精品一区二区三区 | 日本成人中文字幕 | 亚洲欧美激情国产综合久久久 | 中文字幕日韩一区 | 一区二区三区视频在线观看 | 黄色一级网 |