【发布时间】:2020-06-11 17:16:41
【问题描述】:
我正在尝试测试我的 @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 的屏幕已附加
【问题讨论】:
标签: java spring rest redirect localhost