Mariano L :
I have a webapp using Spring-MVC built with Maven. When I generate the JAR file the app start just fine. The controller is execute but when I reach this part:
@RequestMapping(value = "/test-block", method = RequestMethod.GET)
public ModelAndView block(Model model) {
return new ModelAndView("templates/test-block");
}
I get this error:
There was an unexpected error (type=Not Found, status=404).
/WEB-INF/templates/test-block.jsp
Note that debugging or running in the IDE works fine.
My folder:
src
|--main
|--java
|--com.xxx // sources
webapp
|--WEB-INF
|--templates
|--*.jsp // jsp files
resources
|--application.properties
My application properties:
spring.mvc.view.prefix=/WEB-INF/
spring.mvc.view.suffix=.jsp
I checked the generated JAR file and I can't see WEB-INF anywhere.
edit:
pom file:
<packaging>war</packaging>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
Nicholas K :
You should create a .war
rather than a .jar
for a web application and you will see the WEB-INF
folder.
Also change
spring.mvc.view.prefix=/WEB-INF/
to spring.mvc.view.prefix=/WEB-INF/templates
and
ModelAndView("templates/test-block")
to ModelAndView("test-block")
to address the 404 error.