spring boot jsp & 可执行 jar 抛出 /error
Posted
技术标签:
【中文标题】spring boot jsp & 可执行 jar 抛出 /error【英文标题】:spring boot jsp & executable jar throws /error 【发布时间】:2017-07-24 13:05:39 【问题描述】:我正在尝试执行我的 SpringBoot webapp jar,它会抛出找不到页面的错误。 但在 Spring-Too-Suite 上运行时它会正常工作。
我的主要课程
@SpringBootApplication
public class WudiDataApplication
public static void main(String[] args)
SpringApplication.run(WudiDataApplication.class, args);
application.propertie 文件如下
spring.mvc.view.prefix:/WEB-INF/jsp/
spring.mvc.view.suffix: .jsp
server.port=8080
这是我的 pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.wudidata</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>newWudiData</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.3.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-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
....更新....
我已经创建了如下所示的配置类,但仍然显示相同的错误..
@Configuration
@EnableTransactionManagement
@EnableWebMvc
public class DbConfig
.......
【问题讨论】:
【参考方案1】:实际上我们无法在 Spring Boot 中使用 jsp 创建 jar。尝试创建战争,它需要一些特定的文件夹结构
【讨论】:
【参考方案2】:你需要创建一个配置类来启用 web mvc
@Configuration
@EnableWebMvc
public class WebConfig
【讨论】:
我已经创建了如下所示的配置类,但仍然显示相同的错误.. (@Configuration @EnableTransactionManagement @EnableWebMvc) public class DbConfig以上是关于spring boot jsp & 可执行 jar 抛出 /error的主要内容,如果未能解决你的问题,请参考以下文章
如何使用 Spring MVC & Security、Jasig CAS 和 JSP 视图在 Spring Boot 2 中配置 UTF-8?
无法使用 Spring Boot 和 MVC 找到/渲染 JSP 文件