关于springboot正常启动,路由却无法正常访问的问题

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.运行结果 这里写图片描述 这里会看到路由会配置成功

4.出现404无法访问的问题 这里主要有三种情况

*Application.java和你的@controller注解类,不在同一级目录下,@SpringBootApplication默认的扫描位置就是Application所在的同级目录和子目录 注解的导入的类不对,这个自行百度,一般不会出现 这里是我遇到的情况,springboot正常启动,但是路由配置没有生效,最后搞了好久才发现是springboot的版本太低,<version>1.5.9.RELEASE</version>升级了一下版本,问题完美解决,希望能给大家提供点建议。

猜你喜欢

转载自my.oschina.net/u/3053883/blog/1795436