Spring Boot应用程序在执行JAR文件时显示白色标签错误 [英] Spring boot application displaying white label error when executing jar file

查看:69
本文介绍了Spring Boot应用程序在执行JAR文件时显示白色标签错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾尝试在stackoverflow中进行搜索,但无法找到解决我的问题的可行的完美解决方案,因此想在此处发布.

I have tried searching in stackoverflow but couldn't able to find a viable perfect solution to my problem and hence would like to post here.

当我通过eclipse作为spring boot应用程序运行spring boot应用程序时,它运行正常并显示正确的页面.但是,当我转换为可执行jar文件并尝试通过命令提示符"java -jar abc.jar"运行时,该应用程序显示白色标签错误.

When I run my spring boot application via eclipse as spring boot app, it is working fine and displaying proper page. But when I converted into executable jar file and try to run via command prompt "java -jar abc.jar", the application is showing white label error.

这是我的应用程序结构.

Here is my application structure.

我的控制器在这里,

@RestController
@RequestMapping("/")
public class WebController {

@RequestMapping(value="/")
public ModelAndView home() {
    ModelAndView app = new ModelAndView();
    app.setViewName("home2");
    return app;
}
}

我的pom.xml文件

My pom.xml file

<?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.eradar</groupId>
<artifactId>eradar-poc</artifactId>
<version>0.0.2-SNAPSHOT</version>
<packaging>jar</packaging>
<!-- <packaging>war</packaging> -->

<name>eRadarPOC</name>
<description>Demo project for Spring JPA - PostgreSQL - 
AngularJS</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <!-- <version>1.5.4.RELEASE</version> -->
    <version>1.5.9.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>      
   <project.reporting.outputEncoding>UTF8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
    <drools.version>7.3.0.Final</drools.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <scope>runtime</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>

<dependency>
    <groupId>org.apache.tomcat.embed</groupId>
    <artifactId>tomcat-embed-jasper</artifactId>
    <scope>provided</scope>
</dependency>

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jstl</artifactId>
</dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.kie</groupId>
        <artifactId>kie-api</artifactId>
        <version>${drools.version}</version>
    </dependency>
    <dependency>
        <groupId>org.drools</groupId>
        <artifactId>drools-core</artifactId>
        <version>${drools.version}</version>
    </dependency>
    <dependency>
        <groupId>org.drools</groupId>
        <artifactId>drools-compiler</artifactId>
        <version>${drools.version}</version>
    </dependency>
    <dependency>
        <groupId>org.drools</groupId>
        <artifactId>drools-templates</artifactId>
        <version>${drools.version}</version>
    </dependency>
    <dependency>
    <groupId>org.drools</groupId>
     <artifactId>drools-decisiontables</artifactId>
     <version>${drools.version}</version>
   </dependency>

    <dependency>
        <groupId>org.kie</groupId>
        <artifactId>kie-ci</artifactId>
        <version>${drools.version}</version>
     </dependency>

     <dependency>
       <groupId>com.googlecode.json-simple</groupId>
       <artifactId>json-simple</artifactId>
      <version>1.1</version>
    </dependency>

<dependency>
   <groupId>org.json</groupId>
   <artifactId>json</artifactId>
   <version>20080701</version>
</dependency>

    <dependency>
     <groupId>javax.ws.rs</groupId>
    <artifactId>javax.ws.rs-api</artifactId>
   <version>2.0.1</version>
    </dependency>

<!-- https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api -->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>

</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <executable>true</executable>
            </configuration>
        </plugin>
        <!-- Added -->
    <!--  <plugin>
      <groupId>org.apache.tomcat.maven</groupId>
      <artifactId>tomcat7-maven-plugin</artifactId>
      <version>2.1</version>
      <executions>
        <execution>
            <id>tomcat-run</id>
            <goals>
                <goal>exec-war-only</goal>
            </goals>
            <phase>package</phase>
            <configuration>
                <path>/</path>
                <enableNaming>false</enableNaming>
                <finalName>webapp.jar</finalName>
                <charset>utf-8</charset>
            </configuration>
        </execution>
      </executions>
    </plugin> -->
    <!-- Ended -->
    </plugins>
    <finalName>webappexecutableJar</finalName>
</build>

能否请您提出一些解决方案?如果你们遇到了类似我的类似问题,您如何处理?非常感谢.

Can you please suggest some solutions? If you guys have encountered any similar issues like mine, how did you handle? Thanks a lot.

推荐答案

请在您的application.properties中定义前缀和后缀映射,如下所示,然后尝试

Do define the prefix and suffix mapping in your application.properties like below and try

spring.mvc.view.prefix: /WEB-INF/jsps
spring.mvc.view.suffix: .jsp in your application.properties

请检查以下文件中的映射 https://github.com/hellokoding/springboot-jsp/blob/master/src/main/resources/application.properties

Please check the file below for the mapping https://github.com/hellokoding/springboot-jsp/blob/master/src/main/resources/application.properties

还要使用jsp来检查示例springboot项目,如下所示 https: //hellokoding.com/spring-boot-hello-world-example-with-jsp/

Also check the sample springboot project with jsp like below https://hellokoding.com/spring-boot-hello-world-example-with-jsp/

这篇关于Spring Boot应用程序在执行JAR文件时显示白色标签错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆