Unit test Springboot MockMvc returns 403 Forbidden

后端 未结 2 1571
余生分开走
余生分开走 2021-01-12 15:02

I wrote one unit test that tests UsersController. UsersControllerTest.findUser is working fine, but UsersControllerTest.insertGetModifyDelete it doesn\'t.

In the log

2条回答
  •  情书的邮戳
    2021-01-12 15:30

    You can try to debug this program.i think probleam is happend in "mockMvc" object is not autowired.mockMvc object should load from WebApplicationContext in before program run.

    @Autowired
    private WebApplicationContext webApplicationContext
    
    @Before()
    public void setup()
    {
        //Init MockMvc Object and build
        mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
    }
    

提交回复
热议问题