Spring javax.servlet.ServletException:循环视图路径[登录]
我是Spring Boot的新手,希望将Spring安全模块添加到我以前的项目中。我遵循了这一点。我的Spring Boot版本是Spring javax.servlet.ServletException:循环视图路径[登录],spring,spring-boot,spring-security,Spring,Spring Boot,Spring Security,我是Spring Boot的新手,希望将Spring安全模块添加到我以前的项目中。我遵循了这一点。我的Spring Boot版本是1.5.6。发布版 这是安全配置 @Configuration @EnableWebSecurity public class WebSecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) th
1.5.6。发布版
这是安全配置
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/", "/home").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.logout()
.permitAll();
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth
.inMemoryAuthentication()
.withUser("user").password("password").roles("USER");
}
}
以下是MVC配置:
@Configuration
public class MvcConfig extends WebMvcConfigurerAdapter {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/home").setViewName("home");
registry.addViewController("/").setViewName("home");
registry.addViewController("/hello").setViewName("hello");
registry.addViewController("/login").setViewName("login");
}
我可以确保home.html
、hello.html
和login.html
位于resources/templates/
中。在我将Spring安全部分添加到以前的项目中时,我还拥有一个处理jpa请求的控制器
@Controller
@RequestMapping("/test/pgsql")
public class TestPostgreSQLController {
@Autowired
private CustomerRepository customerRepository;
@RequestMapping("/save")
public @ResponseBody
String process() {
customerRepository.save(new Customer("Neo", "Chan"));
customerRepository.save(new Customer("Luke", "Liu"));
customerRepository.save(new Customer("Ran", "Guo"));
customerRepository.save(new Customer("Joey", "Chen"));
customerRepository.save(new Customer("Larry", "Huang"));
return "Done";
}
@RequestMapping("/findbyid")
public @ResponseBody String findById(@RequestParam("id") long id) {
String result = "";
result = customerRepository.findOne(id).toString();
return result;
}
@RequestMapping("/find")
public @ResponseBody String find(@RequestParam("lastname") String lastName) {
String results = "";
for (Customer bauer : customerRepository.findCustomersByLastName(lastName)) {
System.out.println(bauer.toString());
results = results + bauer.toString() + "<br>";
}
return results;
}
}
有什么建议吗?提前谢谢。这个问题问了很久,但我在这里找到了答案] 尝试添加注册表.addViewController(“/login”).setViewName(“login.html”)代码>
这对我来说很有用,希望对我有所帮助。这个问题问了很久了,但我在这里找到了答案] 尝试添加注册表.addViewController(“/login”).setViewName(“login.html”)代码>
这对我来说很有用,希望对我有帮助。我也有同样的问题。问题和pom文件有关,您应该添加Thymeleaf依赖项,代码将开始工作
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
org.springframework.boot
弹簧启动装置
我也有同样的问题。问题和pom文件有关,您应该添加Thymeleaf依赖项,代码将开始工作
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
org.springframework.boot
弹簧启动装置
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>