Spring boot - 白标错误页面 [英] Spring boot - Whitelabel Error Page
问题描述
我是 spring-boot 的新手.我在端口 8080 上启动 spring-boot 应用程序时出错.我得到白标错误页面.
I am new on spring-boot. I have an error when I start my spring-boot application on the port 8080. I get Whitelabel Error Page.
我在 /src/main/resources/templates/ 中创建了一个非常简单的 html 页面.
I have created a very simple html page in /src/main/resources/templates/.
这是我的 pom.xml.
Here is my 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>org</groupId>
<artifactId>MyBanQ</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>MyBanQ</name>
<description>compta Project</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.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-data-jpa</artifactId>
</dependency>
<!-- <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency> -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</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>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
这是我的应用程序的控制器
Here is the controller of my application
public class BanqueController {
@Autowired
private IBanqueMetier banqueMetier;
@RequestMapping("/operations")
public String index()
{
return "comptes";
}
}
应该返回的html是这个
The html that should be return is this one
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>MyBanQ</title>
</head>
<body>
<h3>Test</h3>
</body>
</html>
主要应用如下.我已经尝试了这里提出的解决方案 Springboot Whitelabel 错误页面,但它对我不起作用.
The main application is below. I have tried the solution proposed here Springboot Whitelabel Error Page, but it doesn't work for me.
@SpringBootApplication
public class MyBanQApplication implements CommandLineRunner {
public static void main(String[] args) {
SpringApplication.run(MyBanQApplication.class, args);
}
}
推荐答案
在你的控制器类中添加注解@Controller.你的html文件名应该是comptes",正如你在索引函数中提到的那样.
Add the annotation @Controller to your controller class.And your html file name should be "comptes" as you have mention in your index function.
这篇关于Spring boot - 白标错误页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!