SpringBoot项目启动成功,访问路径提示404

当SpringBoot项目启动成功后,访问Controller下的RequestMapping路径却发现无法访问,且提示Status=404

我的项目中controller下只有一个访问路径/hello,正常情况下当项目启动成功,会在控制台看到项目启动时扫描到该路径:@RequestMapping(value="/hello") ;但是我们看控制台此时并没有扫描到/hello路径

/hello路径无法成功访问

到这里就需要检查你的SpringBoot启动类是否与你的Controoler在同一级目录下,看图,发现到问题了吗?启动类在cn.alin.application下,但是接口在cn.alin.controller下

@SpringBootApplication默认的扫描位置就是Application所在的同级目录和子目录,我们修改一下:

修改完成后,重启项目,此时在控制台发现路径/hello被扫描到了,那么看来成功了

访问接口,成功

总结:

● SpringBoot成功启动,路径无法访问,查看接口是否能被扫描到。
● 如果接口名不能被扫描,查看启动类与Controller层是否保持在同级目录下。
● @SpringBootApplication默认的扫描位置就是Application所在的同级目录和子目录,按照规则修改即可成功访问。

————————————————
版权声明:本文为CSDN博主「崽崽今天学习了吗」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_39934868/article/details/89396273

原文地址:https://www.cnblogs.com/Dm920/p/12502852.html

时间: 2024-08-01 23:47:30

SpringBoot项目启动成功,访问路径提示404的相关文章

springboot项目启动成功后执行一段代码的两种方式

springboot项目启动成功后执行一段代码的两种方式 实现ApplicationRunner接口 package com.lnjecit.lifecycle; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; import org.springframework.core.annotation.Order; import org.sp

第二周——1.1项目启动成功访问网页404

项目部署成功,网页访问却404,须注意:Tomcat配置,URL要与deployment的application context保持一致!! 原文地址:https://www.cnblogs.com/ezreal61/p/11793795.html

Springboot项目启动后访问不到Controller

controller 方法中 @Controller改为 @RestController 原文地址:https://www.cnblogs.com/lixxx/p/11323571.html

J2EE整合Maven开发,Tomcat正常启动,访问链接报404错误

Tomcat7.X正常启动,通过浏览器访问URL时,报404错误.原来是部署时,初了问题,因为使用IDE开发,Eclipse帮我们自动部署了,可有时候会出现问题.解决方案如下: 选中项目,右键:Properties -> Deployment Assembly J2EE整合Maven开发,Tomcat正常启动,访问链接报404错误

Spring boot启动成功后输出提示

添加logback-spring.xml,将log输出到文件,控制台输出的level改为error因此只会出处banner src/main/resources/banner.txt的内容为 start... 但是输出完banner后,spring boot并没有启动完毕 因此,我想在Spring boot启动成功后输出提示 有两种方式 1.实现 ApplicationRunnerImpl eg: package com.example.demo.configure; import org.sp

springboot项目启动之后初始化自定义配置类

前言 今天在写项目的时候,需要再springboot项目启动之后,加载我自定义的配置类的一些方法,百度了之后特此记录下. 正文 方法有两种: 1. 创建自定义类实现 CommandLineRunner接口,重写run()方法.springboot启动之后会默认去扫描所有实现了CommandLineRunner的类,并运行其run()方法. @Component @Order(2) //通过order值的大小来决定启动的顺序 public class AskForLeave implements

springboot项目启动报错 url' attribute is not specified and no embedded datasource could be configured

报错相关信息: 2019-07-22 17:12:48.971 ERROR 8312 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPLICATION FAILED TO START *************************** Description: Failed to configure a DataSource: 'url' attribute is not

第一个springboot项目启动报错Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

报错内容具体如下 *************************** APPLICATION FAILED TO START *************************** Description: Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured. Reason: Failed to determine a

spring boot 项目设置默认访问路径方法

spring boot项目一般通过Application启动,且不需要配置web.xml,所以设置默认访问页面可以通过以下方法实现,比如增加默认DefaultView类,代码如下: import org.springframework.context.annotation.Configuration; import org.springframework.core.Ordered; import org.springframework.web.servlet.config.annotation.