Spring boot instance report 404 issues

Source: Internet
Author: User

Today I suddenly want to write a Hello world to spring boot, after the application successfully started, access to the Http://localhost:8080/hello newspaper 404.

Scenario Description: Controller class Package: Com.yjl.test.controller,,, Spring boot App startup class package: Com.yjl.test.springboot, according to the online search spring The boot application scanning class, so in the application launch class plus @componentscan (Basepackages = {"Com.yjl.test.controller.*"}), the project started successfully, is still reported 404, The s.w.s.m.m.a.requestmappinghandlermapping in the console log also does not have a mapped mapping of "/hello".

Solve:

The class for the spring boot default Scan project is the current package and sub-package of the startup class , and the package that the Controller class belongs to must be a child package of the package that the startup class belongs to. (although there are classes of start-up classes and controllers that can be placed under different packages and then use Componentscan annotations, I did not pass the test ....) )

Place the spring boot startup class under the Com.yjl.test package, and then remove @componentscan (basepackages = {"Com.yjl.test.controller.*"}), the project starts successfully, and the log appears:

S.w.s.m.m.a.requestmappinghandlermapping:mapped "{[/hello],methods=[get]}" onto public java.lang.String Com.yjl.test.controller.TestController.getHello ()

Run successfully ...

Spring boot instance report 404 issues

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.