I'm trying to map all GET
requests to unmapped url of the site to show the index.html
file.
So, I created the following @RestController
:
@RequestMapping(method=RequestMethod.GET)
public String redirectToIndex() {
return "index.html";
}
My index.html
is in resources/static/index.html
. I also tried the following controller:
@RequestMapping(method=RequestMethod.GET)
public String redirectToIndex() {
return "/static/index.html";
}
However, in both cases, browser literally shows the strings index.html
and /static/index.html
respectively instead of showing the html file. I tried a lot of different other approaches to similar questions here but can't get it to resolve... Please help.
EDIT:
My fill @RequestController
class:
@RestController
public class FeedbackController {
@Autowired
private FeedbackService feedbackService;
@RequestMapping(method=RequestMethod.POST, value="/feedback")
public Feedback addFeedback(@RequestBody Feedback feedback) {
return feedbackService.addFeedback(feedback);
}
@RequestMapping(method=RequestMethod.GET)
public String redirectToIndex() {
return "index.html";
}
}
My pom.xml
:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.8.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>