1.用框架先引jar包,现在主流引包方式是maven引入方式。
1.1继承SpringBoot为父项目,这样可以继承很多默认的配置。
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.10.RELEASE</version>
</parent>
1.2引入web启动器模块(其实就是SpringMVC)
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
2.新建Controller,供访问URL测试使用。
@Controller
public class HelloController {
@ResponseBody
@RequestMapping("/testSpringBoot")
public String testSpringBoot(){
System.out.println("Hello SpringBoot!");
return "testSpringBoot";
}
}
3.新建SpringBoot的启动类
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
4.运行main函数,访问localhost:8080/testSpringBoot即可。