久久久久久久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在线播放免费 | 亚洲五码在线 | 亚洲一页 | 蜜臀久久99精品久久久久久宅男 | 九九热re| 国产精品色一区二区三区 | 成人av一区二区三区 | 国产成人91视频 | 国产成人精品久久 | 亚洲草草视频 | 男女免费网站 | 久久久久国产精品 | 亚洲 中文 欧美 日韩 在线观看 | 精品国产一区二区三区性色av | 青草福利 | 99精品久久久 | 伊人网综合在线观看 | 欧美中文一区 | 国产伦精品一区二区三区高清 | 免费黄色的视频 | 国产精品毛片一区二区三区 | 国产精品成人一区二区三区 | 欧美日韩专区 | 亚洲视频免费在线观看 | 日韩一区在线观看视频 | 精品久草 | 久久精品欧美视频 | 五月天天丁香婷婷在线中 | 99久久精品国产毛片 | 成人精品在线视频 | 国产精品久久久久久久模特 | 超碰人人艹| 精品久久久久久久久久久 | 亚洲免费在线视频 | 国产sm主人调教女m视频 | 免费在线精品视频 | 亚洲精品视频在线观看免费 | 91精品久久久久久久久久入口 | 久久视频精品 | 亚洲精品福利视频 | 久久久久久中文字幕 |