Regarding the problem that springboot starts normally, but the routing cannot be accessed normally

pom的配置, <parent> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId> <version>1.5.9.RELEASE</version> </parent> 1 2 3 4 5 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> 1 2 3 4 2.helloApplication.java

@SpringBootApplication @Configuration @Controller public class helloApplication {

@RequestMapping("test")
@ResponseBody
public String hello() {
    return "hello world!!!";
}
public static void main(String[] args) throws Exception {

    System.out.println("springboot-------------------开始启动");
    SpringApplication app=new SpringApplication(helloApplication.class);
    app.setBannerMode(Banner.Mode.OFF);

    app.run(args);
    //SpringApplication.run(TestController.class, args);
    System.out.println("springboot-------------------启动完成");
}

} 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 3. Write a picture description here for the running result and you will see that the route will be configured successfully

4. There are three main situations when there is a 404 inaccessible problem

*Application.java and your @controller annotation class are not in the same level directory. The default scan location of @SpringBootApplication is the same level directory and subdirectory where the Application is located. The imported classes annotated are wrong. This self-Baidu generally does not appear here. In the situation I encountered, springboot started normally, but the routing configuration did not take effect. In the end, it took a long time to find out that the version of springboot was too low. <version>1.5.9.RELEASE</version> upgraded the version, and the problem was solved perfectly. Hope to give you some advice.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324377783&siteId=291194637