在Spring Boot 2中出现'Whitelabel Error Page'错误

时间:2019-11-21 12:11:31

标签: spring-boot tomcat

调用仪表板主页时出现以下错误。http://localhost:8082/web/fix/dashboard

enter image description here

我从中了解到,JSP文件/WEB-INF/jsp/dashboard.jsp某种程度上丢失了,或者也许spring无法找到它,或者我做错了事。

为确保我尝试反编译jar,但缺少JSP文件。不知道在哪里?

我已将JSP文件放置在src/main/webapp/WEB-INF/jsp/dashboard.jsp中。

但是,仅在使用jar文件运行应用程序时才会出现此问题。在日食中工作正常。

java -jar application.jar

这是一个maven项目。

Application.properties

spring.profiles.active=dev
spring.main.allow-bean-definition-overriding=true
server.address=127.0.0.1
server.port=8082
spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp

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 
https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.fidel.fixadaptor</groupId>
<artifactId>fix-adaptor</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>fix-adaptor</name>
<description>Demo project for Spring Boot</description>

<properties>
    <maven.test.skip>true</maven.test.skip>
    <java.version>1.8</java.version>
</properties>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.9.RELEASE</version>
    <relativePath />
</parent>

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

    <dependency>
        <groupId>javax.xml.bind</groupId>
        <artifactId>jaxb-api</artifactId>
    </dependency>

    <!-- <dependency> <groupId>com.sun.xml.bind</groupId> <artifactId>jaxb-core</artifactId> 
        <version>2.3.0</version> </dependency> <dependency> <groupId>com.sun.xml.bind</groupId> 
        <artifactId>jaxb-impl</artifactId> <version>2.3.0</version> </dependency> -->

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

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

    <dependency>
        <groupId>org.quickfixj</groupId>
        <artifactId>quickfixj-core</artifactId>
        <version>2.1.1</version>
    </dependency>

    <dependency>
        <groupId>org.quickfixj</groupId>
        <artifactId>quickfixj-messages-fix50sp2</artifactId>
        <version>2.1.1</version>
    </dependency>

    <dependency>
        <groupId>org.mindrot</groupId>
        <artifactId>jbcrypt</artifactId>
        <version>0.3m</version>
    </dependency>

    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
    </dependency>

    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.6</version>
    </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>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
    </dependency>

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

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

    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

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

控制器

@Controller
@RequestMapping(path = "/web/")
public class WebController {

@Autowired
ConfigurationService configurationService;

@Autowired
private Destination destination;

@Autowired
private Gson gson;

@GetMapping(path = "fix/dashboard")
public String dashBoard(Model model) {

    // view to render
    return "dashboard";
}
}

应用程序类

@SpringBootApplication
@ComponentScan("com.covacap.bloomberg")
public class CovacapTerminalRunner extends SpringBootServletInitializer 
implements CommandLineRunner {

/** The adaptor runner. */
@Autowired
CovacapRunner adaptorRunner;

/** The Constant LOGGER. */
private static final Logger LOGGER = 
LoggerFactory.getLogger(CovacapTerminalRunner.class);

/**
 * The main method.
 *
 * @param args the arguments
 */
public static void main(String[] args) {
    ConfigurableApplicationContext context = 
SpringApplication.run(CovacapTerminalRunner.class, args);
    try {
        String[] list = context.getBeanDefinitionNames();
        for (String string : list) {
            LOGGER.info(string);
        }
        context.getBean(AdaptorDestination.class).autoStart();

    } catch (BeansException | ConfigException e) {
        e.printStackTrace();
    }
}

/**
 * {@inheritDoc}
 * 
 * @param args
 * @throws Exception
 */
@Override
public void run(String... args) throws Exception {
    // adaptorRunner.run(args);
}
}

请对此提供帮助

1 个答案:

答案 0 :(得分:0)

由于缺少jsp文件,并且正如您在反编译jar文件之后提到的那样,没有jsp文件意味着在打包jar文件时,maven不会复制它们。

尝试告诉Maven手动将webapp文件夹复制为类似于 在摘要下方

<build>
    <resources>
      ...
      <resource>
        <directory>src/main/webapp</directory>
      </resource>
      ...
    </resources>
    ...
</build>