Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem that springboot project starts but 404 error is reported by access

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how to solve the problem of springboot project startup but the interview report 404 error. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

Springboot project started, access reported 404 error

When I was working on a springboot project, I wrote it on someone else's project, and after I finished it, I wanted to do a test, so I started springboot, and when I visited, I kept packing 404 errors, and then Baidu took a look at the methods given online, including the use of @ RestController, and then removed the "value=" in the method @ RequestMapping (value= "/ add"). This method is of no use to me because I used @ RestController before my project. And there is no value= in @ RequestMapping.

So, I looked at other methods, saying that the Application started by springboot must be placed outside the controller class, otherwise it could not be scanned. I saw it, and there was nothing wrong with my bag. I was puzzled and entangled for a long time. I asked my colleagues, but it was not solved.

My solution.

Later, I modified the notes I used, and the problem was solved after the revision. I don't know why, but I hope I can give you some help.

Change @ RestController to @ Controller and @ RequestMapping ("/ contractmap"), and the following method notes to @ RequestMapping (value = "/ add") and @ ResponseBody. After startup, you can access it normally. I hope it can help you.

404 caused by springboot version

Recently, I was going to use springboot to build a project, but I encountered a strange 404 problem. After looking for it for a long time, I finally solved it.

Environment description

Eclipse:Oxygen Release (4.7.0)

Maven:3.3.9 (eclipse automatic installation)

Java:1.8

Directly use eclipse to create a new springboot project. After the project is completed, the project pom file reports an error.

The error report is as follows

Checked that maven is not compatible with the version, so change the springboot version to 2.1.1.RELEASE, after the modification, the pom file is normal, the project can also start normally, but web access has been 404, showing that the interface can not be found.

Took a look at the startup log, although the project started successfully, but all the annotation classes were not scanned, so I speculated that there might be something wrong with the startup loading path, so I checked all kinds of materials on the Internet, and I didn't find any problems with the path. So add a comment to the springboot startup class to specify the scan path, but the result is the same, nothing can be scanned.

It is suspected that the springboot project comes with a previous problem with tomcat, then comment out the Tomcat that comes with springboot and run it, and the result is the same.

I also suspected that there was something wrong with the introduction of other jar, or there was something wrong with my own code, so I blocked all the code logic and wrote only a test controller, but it still didn't work. I felt like I was going crazy.

I really couldn't find any reason, so I compared the current project with the original normal project bit by bit, and finally found that the version of spring-boot-starter-parent was different, so I modified the version information and found that everything could be scanned normally and was exasperating.

Spring-boot-starter-parent version from 2.1.1.RELEASE-> 2.0.1.RELEASE

So, if your springboot project encounters 404, if you can't find the reason, you might as well take a look at the version.

This is the end of this article on "how to solve the problem of springboot project startup but access report 404 error". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report