Unit test Springboot MockMvc returns 403 Forbidden
I got around it with @AutoConfigureMockMvc(addFilters = false)
. Please make sure that this won't compromise other functionality on your HTTP stack.
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();
}