Spring не отображает страницы
Спринг не отображает страницы.
При попытке входа на страницу выдает ошибку:
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Circular view path [registration]: would dispatch back to the current handler URL [/registration] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)] with root cause
Пробовал freemarker просто на html поменять, чтобы хоть какое-то отображение было. То же самое...
Ссылка на гитхаб проекта: https://github.com/MikTop/WebTest
Основные классы:
MainController
package com.example.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class MainController {
@GetMapping("/")
public String mainPage() {
return "index";
}
@GetMapping("/login")
public String login() {
return "login";
}
}
RegistrationController
package com.example.controller;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import com.example.domain.User;
import com.example.repo.UserRepo;
@Controller
public class RegistrationController {
@Autowired
private UserRepo userRepo;
@GetMapping("/registration")
public String registration() {
return "registration";
}
@PostMapping ("/registration")
public String addNewUser(User user, Map<String, Object> model) {
User userFromDB = userRepo.findByUsername(user.getUsername());
if (userFromDB != null) {
model.put("message", "User Exist");
return "registration";
}
userRepo.save(user);
return "login";
}
}
common.ftl
<#macro page>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Shop</title>
</head>
<body>
<#nested>
</body>
</html>
</#macro>
index.ftl
<#import "parts/common.ftl" as c>
<@c.page>
<h1>Hello at our shop</h1>
<a href="/registration">Add new user</a>
<a href="/login">Sign in</a>
</@c.page>
SecurityConfig
package com.example.security;
import javax.activation.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.SecurityBuilder;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.WebSecurityConfigurer;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.crypto.password.StandardPasswordEncoder;
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter{
@Autowired
private UserDetailsService userDetailsService;
@Bean
public BCryptPasswordEncoder encoder() {
return new BCryptPasswordEncoder(4);
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService).passwordEncoder(encoder());
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/**").permitAll()
// .anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.logout()
.permitAll();
}
```