HTTP-ответ 404 в Spring Boot - PullRequest
       1

HTTP-ответ 404 в Spring Boot

0 голосов
/ 01 ноября 2019

Я пытаюсь написать простую аутентификацию в Spring Security. Мне понравилось это руководство https://spring.io/guides/gs/securing-web/. После запуска приложения и успешного переключения на / регистрацию в браузере, я ввожу все данные в форму, после нажатия кнопки регистрации появляется следующее сообщение: «Произошла непредвиденная ошибка (type = Not Found, status = 404). Нет доступных сообщений "

После попытки переключения на / регистрацию IDEA только пишет:

Инициализация Spring DispatcherServlet 'dispatcherServlet'

Инициализация сервлета 'dispatcherServlet'

До этого была проблема с типом данных application / x-www-form-urlencoded с тем же @RequestMapping (value = "/ registration"). Который избавился от сказанного здесь: https://github.com/spring-projects/spring-framework/issues/22734

Мне нужна помощь профессионалов.

@RequestMapping(value = "/registration", method = RequestMethod.GET)
public String regPage(){
    return "registration";
}

@RequestMapping(value = "/registration", method = RequestMethod.POST, consumes = "application/json")
public String  registration(@RequestBody User user) throws Exception {
    if (userRepository.findByUsername(user.getUsername()) != null)
        throw new UsernameNotFoundException(String.format("The username %s does not exist", user.getUsername()));

    user.setRoles(Collections.singletonList(Role.USER));
    user.setActivationCode(UUID.randomUUID());
    user.setActive(true);
    userService.addUser(user);
    senderService.send(user.getEmail(), "Network Planinng Tool Activation", "Link for activation: http://localhost:8080/activation/" + user.getActivationCode());
    return "Register message was sent.";
}

/* without this method I have en problem with application/x-www-form-urlencoded*/
@RequestMapping(value = "/registration", method = RequestMethod.POST, consumes = "application/x-www-form-urlencoded")
public String  reg(User user) throws Exception {
    return "Register message was sent.";
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...