Spring Boot Whitelabel错误页面(类型=找不到,状态= 404) [英] Spring Boot Whitelabel Error page (type=Not Found, status=404)
问题描述
下午好!我正在开始春季学习,我以相同的方式遵循教程,但是它返回错误:
Good afternoon! I'm starting spring studies, I'm following a tutorial the same way, but it returns an error:
文件夹结构:
奇怪的是:如果我将"EventoController.java"插入br.com.SpringApp.SpringApp,它将正常工作.
The strange thing is: If I insert the "EventoController.java" into br.com.SpringApp.SpringApp, it works correctly.
package br.com.SpringApp.SpringApp;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SpringAppApplication {
public static void main(String[] args) {
SpringApplication.run(SpringAppApplication.class, args);
}
}
.
package br.com.SpringApp.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class EventoController {
@RequestMapping("/cadastroEvento")
public String form() {
return "evento/formEvento";
}
}
根据要求,我要添加pom.xml
As requested, I'm adding 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>br.com.SpringApp</groupId>
<artifactId>SpringApp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>SpringApp</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.10.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-thymeleaf</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>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
有人可以告诉我我错了吗?
Can someone tell me where I'm wrong, please?
推荐答案
请确保您的主类位于其他类之上的根包中.
Make sure that your main class is in a root package above other classes.
当您运行Spring Boot应用程序(即带有@SpringBootApplication注释的类)时,Spring将仅扫描主类包下方的类.
When you run a Spring Boot Application, (i.e. a class annotated with @SpringBootApplication), Spring will only scan the classes below your main class package.
所以您的声明是这样的
程序包br.com.SpringApp.SpringApp;
在这个主类中,即SpringAppApplication
package br.com.SpringApp.SpringApp;
inside this main class i.e SpringAppApplication
程序包br.com.SpringApp.SpringApp.controller;
控制器的名称,即EventoController&indexControllers
package br.com.SpringApp.SpringApp.controller;
name of your controllers i.e EventoController & indexControllers
程序包br.com.SpringApp.SpringApp.model;
您的模型名称,即Evento
package br.com.SpringApp.SpringApp.model;
name of your models i.e Evento
此后清理项目并重新运行spring boot应用程序;
After This clean your project and re-run spring boot application;
这篇关于Spring Boot Whitelabel错误页面(类型=找不到,状态= 404)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!