这是我的配置。
的pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
...
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>{MainClass}</mainClass>
<layout>JAR</layout>
<attach>true</attach>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
</project>
application.properties
spring.mvc.view.prefix=/WEB-INF/views/
spring.mvc.view.suffix=.jsp
在IntelliJ中,它运作良好。 但是当我使用java命令运行时
java -jar myapp.jar
路径中找不到JSP文件。 我用Google搜索了这个问题。然后我把jar换成了战争。 但它没有用。 我该怎么办? 不应该在JSP中使用可执行jar?
这是一个日志。 (使用java命令运行时)
No matching bean found for view name 'user/ticket_list'
No matching bean found for view name 'user/ticket_list.html'
Returning [org.springframework.web.servlet.view.JstlView: name 'user/ticket_list'; URL [/WEB-INF/views/user/ticket_list.jsp]] based on requested media type 'text/html'
Rendering view [org.springframework.web.servlet.view.JstlView: name 'user/ticket_list'; URL [/WEB-INF/views/user/ticket_list.jsp]] in DispatcherServlet with name 'dispatcherServlet'
这是log(使用intellij
运行时)No matching bean found for view name 'user/ticket_list'
Returning [org.springframework.web.servlet.view.JstlView: name 'user/ticket_list'; URL [/WEB-INF/views/user/ticket_list.jsp]] based on requested media type 'text/html'
Rendering view [org.springframework.web.servlet.view.JstlView: name 'user/ticket_list'; URL [/WEB-INF/views/user/ticket_list.jsp]] in DispatcherServlet with name 'dispatcherServlet'
Added model object 'locations' of type [java.util.ArrayList] to request in view with name 'user/ticket_list'
Added model object 'location' of type [java.lang.String] to request in view with name 'user/ticket_list'
Added model object 'tickets' of type [java.util.ArrayList] to request in view with name 'user/ticket_list'
Forwarding to resource [/WEB-INF/views/user/ticket_list.jsp] in InternalResourceView 'user/ticket_list'
Successfully completed request