简体   繁体   中英

Whitelabel error when running with jar file, but works fine with war file and when run with command mvn spring-boot:run


I have a spring boot project which works fine on STS and there were no errors or warning when I created the jar file. But, when I run the project through the command line using the command java -jar project.jar and access through a browser, I get Whitelabel error.

Below is the error

I then run the project using maven command, mvn spring-boot:run, it went well again. There were no errors. I have searched for similar problems on stack overflow, I modified prefix and suffix of my jsp pages, but it still does not work. I wrote a print statement in my function to check if the controller is actually hit and found out that, it is actually able to hit the API and print the statement inside the method, but failing to identify the jsp page.

Please help me identify the mistake I am making, and why it works for maven command, and why not with a jar file or does it make any difference if I run through war file. Here are some of the code details:

POM 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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.3.1.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.project</groupId>
<artifactId>Project.V-1.3</artifactId>
<version>V-1.3</version>
<name>Project</name>
<description>Project - Launching on AWS</description>
<properties>
    <java.version>1.8</java.version>
    <spring-cloud.version>Hoxton.SR5</spring-cloud.version>
</properties>

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

   <dependency>
 <groupId>com.amazonaws</groupId>
 <artifactId>aws-java-sdk-s3</artifactId>
 </dependency>

<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jasper</artifactId>
<version>9.0.36</version>
</dependency>

<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.13.1</version>
</dependency>

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

<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.2</version>
</dependency>

    
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jdbc</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web-services</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-webflux</artifactId>
    </dependency>       
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <scope>runtime</scope>
    </dependency>
    
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>org.junit.vintage</groupId>
                <artifactId>junit-vintage-engine</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
</dependencies>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>${spring-cloud.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <executable>true</executable>
            </configuration>
        </plugin>
    </plugins>
 </build>
 </project>

Project directory

Application.properties file

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

My Controller

@Controller
public class HomeController {
@RequestMapping("/")
public ModelAndView home() {
    ModelAndView home_model = new ModelAndView();
    System.out.println("Home Page is hit");
    home_model.setViewName("homePage");
    return home_model;
} }

I see this below on CMD:

CMD log

But when it shows the White label error on the browser as shown in image 1.

I do not know why its not working. But you could try deploying it as a war packaging. You could also try with maven command like mvn spring-boot:run.

Try this: Why if I start a spring boot app as Java Application from the IDE (Eclipse) it works but when I start it from CMD it get me Whitelabel Error?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM