簡體   English   中英

Groovy spock 測試用例找不到自動裝配的 bean

[英]Groovy spock test case cant find autowired beans

我有以下 package 和類的結構: package com.abc.xyz.main.flow 有兩個類:

 ProcessA.java
 ProcessB.java
 

現在 ProcessB 為:

     public class ProcessB{
     
     @Autowired
     ServiceX serviceX;
     @Autowired
     ServiceY serviceY;
     
}

package of ServiceX is: com.abc.xyz.main.adm.service package of ServiceY is: com.abc.xyz.main.cmn.service

 I am writing groovy test case of ProcessA.java
 
package com.abc.xyz.main.flow


@SpringBootTest(classes = TestConfig.class)
@AutoConfigureMockMvc
public class ProcessASpec extends Specification {
  //mocking code for ProcessA class
}

運行時出現錯誤:com.abc.xyz.main.flow.ProcessB 中的 Field serviceX 需要 ServiceX 類型的 bean

如何解決

嘗試將此添加到您的 Class 測試中:

@TestConfiguration
   static class ConfigurationClass{
  
        @Bean
        public ServiceX serviceX() {
            return new ServiceX();
        }
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM