Java DispatcherServlet:在本地主机的页面上重定向
我正在测试@RestController的重定向能力 为了测试aims,它必须在本地主机上重定向Java DispatcherServlet:在本地主机的页面上重定向,java,spring,rest,redirect,localhost,Java,Spring,Rest,Redirect,Localhost,我正在测试@RestController的重定向能力 为了测试aims,它必须在本地主机上重定向 @RestController @RequestMapping(value = RegistrationRestController.CONFIRM_REGISTRATION_URL, produces = MediaType.APPLICATION_JSON_VALUE) public class RegistrationRestController { public static final
@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>
但我收到一个404错误
当我使用真实站点的绝对路径(例如“”)而不是“access_approved”时,它工作得很好
因此,问题集中在页面上,它位于我的项目结构中。此外,我的wabapp屏幕已附加
使用
MockMvc
测试控制器。以下是一个例子:
http://localhost:8080/test/confirmRegistration?token=a5582f4c-db3c-4d7c-9fab-7fd82ffb5d89