Spring Boot Controller 404

前端 未结 1 2005
误落风尘
误落风尘 2021-01-05 06:34

I am fairly new in Spring Boot and trying to build a simple web app. I have defined a controller class containing my mapping for url, but on browser it is giving me a white

相关标签:
1条回答
  • 2021-01-05 06:43

    The BmsApplication class is placed under the com.wellmanage.bms package and by default the @SpringBootApplication annotation runs component scan using this package as the root. Since the BookController is inside com.wellmanage.controller, the package is omitted by default configuration.

    You have two options:

    1. Change default component scan settings and set which package would you like to scan:
        @ComponentScan("com.wellmanage")
        @SpringBootApplication
        public class BmsApplication {
    
            public static void main(String[] args) {
                SpringApplication.run(BmsApplication.class, args);
            }
        }
    
    1. Move the main Application class to root package of you app so that all components which you want to scan automatically are under its package, e.g. to com.wellmanage.

    From the configuration you have posted, it seems you didn't set any template engine. Returning the String "abc" from your controller is hence ignored.

    0 讨论(0)
提交回复
热议问题