我正在尝试构建一个 Spring MVC 项目,并且在尝试解决以下错误时遇到了一些麻烦。
HTTP 状态 500 - 循环视图路径 [login]:将再次分派回当前处理程序 URL [/login]。检查您的 ViewResolver 设置!(提示:由于默认视图名称生成,这可能是未指定视图的结果。)
我通过终端输入了以下命令:
mvn clean package
java -jar target/sprint2-0.1.0.jar
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.teamvirus.src</groupId>
<artifactId>sprint2</artifactId>
<version>0.1.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>0.5.0.M6</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--><dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring3</artifactId>
</dependency>-->
</dependencies>
<properties>
<start-class>com.teamvirus.src.Application</start-class>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-milestone</id>
<url>http://repo.spring.io/libs-milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-milestone</id>
<url>http://repo.spring.io/libs-milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>
登录控制器.java
package com.teamvirus.src;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@Controller
public class LoginController {
@RequestMapping("/login")
public String login() {
return "login";
}
@RequestMapping("/authenticate")
public String authenticate(
@RequestParam(value = "username", required = true) String username,
@RequestParam(value = "password", required = true) String password) {
if ((username.equals("admin") && password.equals("admin")))
return "redirect:dashboard?username=" + username;
else if ((username.equals("student1") && password.equals("student1"))) {
return "redirect:dashboard?username=" + username;
}
return "wrongpassword";
}
}
感谢提供的任何帮助。
编辑:
应用程序.java
package com.teamvirus.src;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.context.annotation.ComponentScan;
@ComponentScan
@EnableAutoConfiguration
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}