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.javajava
@SpringBootApplication @Configuration @Controller public class helloApplication {web
@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.运行结果 这里写图片描述 这里会看到路由会配置成功spring
4.出现404没法访问的问题 这里主要有三种状况springboot
*Application.java和你的@controller注解类,不在同一级目录下,@SpringBootApplication默认的扫描位置就是Application所在的同级目录和子目录 注解的导入的类不对,这个自行百度,通常不会出现 这里是我遇到的状况,springboot正常启动,可是路由配置没有生效,最后搞了很久才发现是springboot的版本过低,<version>1.5.9.RELEASE</version>升级了一下版本,问题完美解决,但愿能给你们提供点建议。app