I'm putting together a webapp using SpringBoot.
The REST part works fine, but the "JSP part" is borked. The endpoints are called, everything is fine until I return the basename of the JSP page, such as return "info"; The method returns a String.
When I invoke an endpoint, I get this message:
[...] [dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Could not resolve view with name 'info' in servlet with name 'dispatcherServlet'] with root cause javax.servlet.ServletException: Could not resolve view with name 'info' in servlet with name 'dispatcherServlet'
I followed "the pattern" for adding JSP support to SpringBoot (I say "the pattern" because the dozen or so sources I found all seem to quote the same example).
I'm building a JAR with Maven, looking into that jar, I don't find the JSP files, or even any of the WEB-INF directory structure, so I believe the problem is somewhere between Maven and SpringBoot's plugin.
Here are the pieces of the POM, most of the dependencies removed:
<packaging>jar</packaging>
...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
...
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
The POM was built mostly from an archetype.
I'm rather ignorant about debugging Maven builds, assuming that this is a Maven problem, however, I suppose it could have something to do with the springboot plugin. I appreciate all assistance, include better resources to read than the ones that I found.
UPDATE Per Qiu Zhou's comment about the , I added the following to the POM:
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
and moved the JSP directory to src/main/resources/WEB-INF/jsp. The JAR file now contains this:
BOOT-INF/classes/WEB-INF/jsp/info.jsp
which seems to be correct. I no longer get the dispatcherServlet message (see above), however, when I curl the site, this is what I get:
% curl localhost:8099/info
{"timestamp":"2020-09-01T17:22:28.413+00:00","status":404,"error":"Not Found","message":"","path":"/info"}
The controller code is this:
@Controller
public class SimpleController {
@GetMapping("/info")
public String info() {
return "info";
}
}
I remain perplexed -- Is the JAR built correctly?? Thanks