我这样设置了测试
@SpringBootTest
@AutoConfigureMockMvc
@RunWith( SpringRunner.class )
public class PublicControllerTest {
@Autowired
private MockMvc mvc;
这是我的控制器签名
@GetMapping( produces = MediaTypes.HAL_JSON_VALUE )
ResponseEntity<ResourceSupport> index( final HttpRequest request ) {
现在它似乎正在注入一个代理值,但是如果你调用request.getURI()
例如,它似乎为空。
我正在尝试这样做,以便我可以将请求传递给UriComponentsBuilder.fromHttpRequest( )
,这是由先前调用的linkTo
我的控制器中的方法,但它们没有获得代理/空值。
如何获取 HttpRequest? (注意:我不想/不能使用HttpServletRequest
它通过得很好,但不是正确的接口UriComponentsBuilder
所以我可以使用HttpServletRequest
@GetMapping( produces = MediaTypes.HAL_JSON_VALUE )
ResponseEntity<ResourceSupport> index( final HttpServletRequest request ) {
但它必须被包裹起来?经过ServletServerHttpRequest
得到我想要的界面。
HttpRequest httpRequest = new ServletServerHttpRequest( request )
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)