I am trying a quick prototype using Spring boot.
I have the following Controller code minus the imports
@EnableAutoConfiguration
@RestController
@Controller
public class IndexController{
@RequestMapping(value = "/")
public ModelAndView firstPage(HttpServletRequest request, HttpServletResponse response){
ModelAndView mv = new ModelAndView("index");
mv.addObject("message", Calendar.getInstance().getTime().toString());
return mv;
}
@RequestMapping(value="/gotoNextPage",method = RequestMethod.GET)
public ModelAndView gotoNextPage(HttpServletRequest request, HttpServletResponse response){
System.out.println("Inside gotoNextPage!!!!!!");
ModelAndView mv = new ModelAndView("redirect:nextpage");
mv.addObject("message", "next page");
return mv;
}
}
From my HTML, I invoke the /gotoNextPage and in my Server, I see the Inside gotoNextPage!!!! print statement. However, the nextPage doesn't load. If I don't use redirect and I type http://localhost:8080/gotoNextPage, the HTML content loads fine. Also, the index.html also loads fine
I am using spring boot mvc, thymeleaf, angularjs
My project structure is shown below: enter image description here
My POM XML file dependencies are shown below:
<?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>ng-spring-boot-helloworld</groupId>
<artifactId>ng-spring-boot-helloworld</artifactId>
<version>1.0.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.0.RELEASE</version>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.3.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>1.2.7.RELEASE</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
</project>
Please help.
Thanks in advance.
redirect:should lead to a valid URL not a view name... And stop mixing versions you are mixing Spring Boot 1.2.0 and 1.2.7. Change the parent to 1.2.7 and remove the versions elsewhere.@RestControllerand@Controllerwhich is it... Judging from your return types you need@Controllernot@RestController. Also the@EnableAutoConfigurationis useless on this class.