gpt4 book ai didi

java - spring-webmvc 升级出现 NoSuchMethodError

转载 作者:太空宇宙 更新时间:2023-11-04 09:09:15 24 4
gpt4 key购买 nike

我们升级到spring-webmvc 5.2.3.RELEASE
这会导致 JUnit 失败。
我认为问题出在 .build() 方法上 - 找不到它。

代码:

@RunWith(MockitoJUnitRunner.class)
public class CommunicationDeliveryControllerTest {

@InjectMocks
CommunicationDeliveryController controller = new CommunicationDeliveryController();

@Mock
private RequestHandler requestHandler;

@Mock
private HttpServletRequest httpServletRequest;

private MockMvc mockMvc;
private Gson gson = new Gson();
private CommunicationDeliveryController spiedController;

@Before
public void setup() {
spiedController = spy(controller);
mockMvc = standaloneSetup(spiedController).build();
}

@Test
public void initiateBatchRunTest() throws Exception{
MvcResult result = mockMvc.perform(post("/api/BatchRun").contentType(MediaType.APPLICATION_JSON_VALUE).content(gson.toJson(BulkCommunicationRequestData.getBulkEmailRequestForPositive()))).andReturn();
assertEquals(HttpStatus.OK.value(), result.getResponse().getStatus());
}

@Test
public void deliverCommunicationTest() throws Exception{
MvcResult result = mockMvc.perform(post("/api/deliverCommunication").contentType(MediaType.APPLICATION_JSON_VALUE).content(gson.toJson(BulkCommunicationRequestData.populateAllEmailDetail()))).andReturn();
assertEquals(HttpStatus.OK.value(), result.getResponse().getStatus());
}
}

错误:

java.lang.NoSuchMethodError: org.springframework.test.web.servlet.setup.StandaloneMockMvcBuilder$StandaloneConfiguration.getInterceptors()[Ljava/lang/Object;
at company.custcomm.service.communicationdelivery.controllers.CommunicationDeliveryControllerTest.setup(CommunicationDeliveryControllerTest.java:45)

我们的 spring-webmvc、mockito 和 JUnit 版本之间是否存在兼容性问题?

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.2.3.RELEASE</version>
</dependency>

最佳答案

我将所有spring依赖升级到4.3.18-RELEASE,然后就没有错误了。

关于java - spring-webmvc 升级出现 NoSuchMethodError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59865132/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com