私はスプリングブートアプリケーションを実行しようとしていますが、404エラーが見つかりません。スプリングブート404が見つかりませんでしたエラー
プロジェクト構造:
src/
+- main/
+- java/
| + com/
| + demo/
| SpringBootDemo.java
| + controller/
| HomeController.java
+- resources/
| application.yml
src/
+- main/
+- webapp/
+- WEB-INF/
+- pages/
| home.jsp
HomeController.java
package com.demo.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class HomeController {
@GetMapping("/")
public String getHome() {
System.out.println("Controller");
return "home";
}
}
application.yml
server:
port: 8080
spring:
mvc:
view:
prefix: /WEB-INF/pages/
suffix: .jsp
build.gradle
buildscript {
ext {
springBootVersion = '1.5.6.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'application'
mainClassName = 'com.demo.SpringBootDemo'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
// In this section you declare where to find the dependencies of your project
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
testCompile('org.springframework.boot:spring-boot-starter-test')
compile('org.springframework.boot:spring-boot-starter-parent')
compile('javax.servlet.jsp.jstl:javax.servlet.jsp.jstl-api')
}
jar {
manifest {
attributes(
'Main-Class': 'com.demo.SpringBootDemo'
)
}
}
SpringBootDemo.java
package com.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication(scanBasePackages="com.demo")
public class SpringBootDemo {
public static void main(String[] args) {
SpringApplication.run(SpringBootDemo.class, args);
}
}
home.jspを
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Hello</title>
</head>
<body>
Hello World
</body>
</html>
私はコードを実行しようとすると、それは
Controller
として出力に表示されますが、ときに私、それはWhitelabel Error Page
を与えます訪問http://localhost:8080/
あなたはこれを読むことがありますか? https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-jsp-limitationsアプリケーションをどのように構築して実行しますか?私はあなたのgradleビルドにwarプラグインが適用されていないことを知っているので、ドキュメンテーションからこの重要な警告を無視した可能性が高いでしょう」。 –