Spring MVC & Maven Integration

spring-boot, spring-mvc

Solution

You are entirely relying on Spring Boot to configure everything, although this shouldn't be a problem for your current view it is.

By default Spring boot registers an `InternalResourceViewResolver` however without any prefix/suffixes. (See the source). Assuming you have your views in `/WEB-INF/views` and they are `jsp` files do the following

- In `src\main\resources` add an `application.properties` file

- Add a property `spring.view.prefix` with the value `/WEB-INF/views/`

- Add a property `spring.view.suffix` with the value `.jsp'

Repackage and start your application.

If you don't have this additional configuration `/login` will lead back to `/login` which will lead back to `/login` which will lead back to `/login` which will... Well you get the picture I guess. (`login` is the name of the view you are referring to from your `@Controller`).

Problem

I'm trying to build a Spring MVC project and am having some troubles trying to resolve the follow error. HTTP Status 500 - Circular view path [login]: would dispatch back to the current handler URL [/login] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.) I entered the following commands via Terminal: 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> ``` LoginController.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"; } } ``` Appreciate any assistance rendered. Edit: Application.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); } } ```

Original source

Related problems