gpt4 book ai didi

spring - MockMvc 和用户主体

转载 作者:行者123 更新时间:2023-12-04 20:16:43 24 4
gpt4 key购买 nike

我尝试测试注入(inject) UserPrincipal 的 mvcControllers 的访问:

restPockMockMvc .perform(get("/pocs").principal(authToken)) .andReturn();

这是我尝试测试的 Controller 方法:

@PreAuthorize(value = "hasRole('AK_ADMIN')") @RequestMapping(method = RequestMethod.GET, produces = "application/json; charset=utf-8") 公共(public) PagedResources 集合列表(HttpServletRequest httpServletRequest){........................

httpServletRequest.getUserPrincipal() 始终为空,而我注入(inject)了 userPrincipal,但我不明白为什么...

欢迎您的帮助。谢谢

最佳答案

尝试

MockHttpServletRequest request = new MockHttpServletRequest();
request.getUserPrincipal();

关于spring - MockMvc 和用户主体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29340971/

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