Spring boot application displaying white label error when executing jar file

扶醉桌前 提交于 2019-12-24 09:58:42

问题


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.

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.

My controller here,

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

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

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.


回答1:


Make sure that you have below dependencies in your POM

 <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>

check your application.properties and add

spring.mvc.view.prefix=/WEB-INF/jsps/
spring.mvc.view.suffix=.jsp



回答2:


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

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

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



来源:https://stackoverflow.com/questions/47880927/spring-boot-application-displaying-white-label-error-when-executing-jar-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!