spring-boot可执行war / jar找不到JSP,但在intellij IDE中它可以工作

时间:2017-01-19 09:59:41

标签: maven jsp intellij-idea spring-boot

这是我的配置。

的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

1 个答案:

答案 0 :(得分:1)

Boot不支持可执行JAR中的JSP。

过去使用黑客/解决方法可能有用,但始终记录在案JSP limitationsspring-boot#8022