java - DispatcherServlet:在 localhost 的页面上重定向
问题描述
我正在尝试测试我的@RestController 重定向能力。
对于测试目标,它必须在 localhost 上重定向。
@RestController
@RequestMapping(value = RegistrationRestController.CONFIRM_REGISTRATION_URL, produces =
MediaType.APPLICATION_JSON_VALUE)
public class RegistrationRestController {
public static final String CONFIRM_REGISTRATION_URL = "/confirmRegistration";
@Autowired
UserService userService;
@GetMapping
public RedirectView confirmRegistration(@RequestParam("token") String token) {
RedirectView redirectView;
Token verificationToken = userService.getToken(token);
if ((verificationToken == null) || (verificationToken.getExpiryDateTime().isAfter(LocalDateTime.now()))) {
redirectView = new RedirectView("access_denied");
} else redirectView = new RedirectView("access_approved");
return redirectView;
}
}
Servlet 映射为:
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
我运行应用程序并输入:
http://localhost:8080/test/confirmRegistration?token=a5582f4c-db3c-4d7c-9fab-7fd82ffb5d89
但我收到 404 错误。
当我使用真实站点的“access_approved”绝对路径(例如“ https://stackoverflow.com/ ”)代替它时,它运行良好。
因此,问题集中在位于 my-project-structure 的页面上。此外,我的 wabapp 的屏幕已附加
解决方案
用于MockMvc
测试控制器。这是一个例子:
https ://howtodoinjava.com/spring-boot2/testing/spring-boot-mockmvc-example/
推荐阅读
- python - 从另一个文件检查对象实例类型
- javascript - 将下拉列表从 Python 重新填充到 jQuery 网页
- sql - 在 TSQL 中拆分字符串文本
- python - 预期 conv2d_input 有 4 个维度,但得到了形状为 (1, 1, 1, 150, 75, 3) 的数组?
- android - 在 android kotlin 中将 Cloud Firestore 数据预先写入纯文本
- python - 无法使用 JWK 签名创建 JWT
- python - 查找列表中唯一的唯一值
- php - 使用多维矩阵生成多个字符串
- python - 调整脚本以计算执行的操作
- regex - 使用正则表达式捕获单个表情符号