记SpringBoot 遇到的Whitelabel Error Page

第一次接触SpringBoot,根据官网在pom.xml中导入相应依赖后,首先,新建controller包,在其中写HelloController类:

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@Controller
public class HelloController {
    @ResponseBody
    @RequestMapping("/hello")

public String sayHello()
    {return "hello,This is my first Spring Boot.";}
}

再写MyBootRun类,用它的主方法来运行Boot:

package com.bit.springboot.po;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class MyBootRun {

    public static void main(String[] args) {
        SpringApplication.run(MyBootRun.class,args);
    }

}

这时执行主方法,控制台的输出为:
在这里插入图片描述
在这里插入图片描述
它说应用程序启动失败。
配置为监听端口8080的Tomcat连接器启动失败。端口可能已经在使用中,或者连接器可能配置错误。
要解决这个问题,需要验证连接器的配置,识别并停止正在监听端口8080的任何进程,或将此应用程序配置为监听另一个端口。
在cmd命令行使用“netstat -ano”,查看端口状态:
在这里插入图片描述
可以看到我的8080端口是被3508应用进程占用着。
还可以用命令netstat -aon|findstr “8080"快速查找。在这里插入图片描述
找到进程之后,就需要去结束它,即可解决8080端口被占用的问题。
在这里插入图片描述
这时再去执行主方法。…一件神奇的事情出现了,我的8080端口又被占用了,这回PID是6655,查看任务管理器,又是java.exe…于是再去任务进程中关闭java.exe,再去执行主方法,这时,在浏览器输入:http://localhost:hello,显示结果:
在这里插入图片描述
这是第二种错误,根据别人的博客,我意识到这个是项目目录的问题,SpringBoot读取不到映射。我的项目目录是这的:
在这里插入图片描述
哦,我犯了个错误,把MyBootRun类放在了po包下,po持久层应该是用来放映射成的类的。现在改变目录结构,把MyBootRun类放在com.bit.springboot包下:
在这里插入图片描述
(又发生了一次java.exe占用8080端口的问题,又去任务管理器中将它结束。)
在浏览器的url栏中输入"http://localhost:8080/hello”:
在这里插入图片描述
Okay,现在问题解决。

发布了47 篇原创文章 · 获赞 1 · 访问量 1276

猜你喜欢

转载自blog.csdn.net/weixin_41750142/article/details/102486033