无法实例化[org.springframework.mobile.device.Device]:指定的类是一个接口

时间:2017-08-04 14:19:39

标签: java spring spring-boot junit

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());
    }

0 个答案:

没有答案