addFreePostTest()方法测试失败。 我无法注入Device bean。 我该如何解决这个问题?
org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.mobile.device.Device]: Specified class is an interface
BoardRestController.class
@RestController
@RequestMapping("/api/board/free")
public class BoardRestController {
@PostMapping("")
public FreePostWriteResponse addFreePost(
@Valid @RequestBody FreePostForm form,
Device device) {
}
BoardRestControllerTests.class
@RunWith(SpringRunner.class)
@WebMvcTest(BoardRestController.class)
public class BoardRestControllerTests {
@Autowired
private MockMvc mvc;
@MockBean private BoardFreeService boardFreeService;
@Test
@WithMockUser
public void addFreePostTest() throws Exception {
FreePostForm form = FreePostForm.builder()
.subject("Subject.")
.content("Content.")
.categoryCode(JakdukConst.BOARD_CATEGORY_TYPE.FOOTBALL)
.build();
mvc.perform(post("/api/board/free")
.contentType(MediaType.APPLICATION_JSON)
.content(ObjectMapperUtils.writeValueAsString(form)))
.andExpect(status().isOk());
}