解决第一个Springboot项目中出现的Whitelabel Error Page

31 篇文章 0 订阅
This application has no explicit mapping for /error, so you are seeing this as a fallback.

Tue Dec 01 10:45:13 CST 2020
There was an unexpected error (type=Not Found, status=404).

跟着网上的教程来写自己的第一个Springboot项目时,发现出现过404,根据这个情况自己去找教程,然后做了一份图解。

自己创建的目录,方便理解。注意SpringbootApplication所在的包,它接管了同级和子目录的RestController,如果不满足这个条件,那么就会爆错。
在这里插入图片描述

first.java不在Springbootapplication.java的同级目录和其子目录下,所以报错。
package first;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class first {

    @RequestMapping("/first")
    public  String  hi(){
        return "你好,检查Springboot启动项目录结构,成功";
    }

}

在这里插入图片描述

second.java在Springbootapplication.java的同级目录和其子目录下,所以运行正常。
package first.second;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class second {

    @RequestMapping("/second")
    public  String  hi(){
        return "你好,检查Springboot启动项目录结构,成功";
    }
}

在这里插入图片描述

third.java在Springbootapplication.java的同级目录和其子目录下,所以运行正常。

package first.second.third;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class third {
@RequestMapping("/third")
    public String hi(){
        return "你好,检查Springboot启动项目录结构,成功";
    }
}

在这里插入图片描述

所以Springbootapplication在那里可以随意一点,但是尽量在最外层,这样可以接管更多的东西。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值