使用Spring Boot框架可以大大加速Web应用的开发过程。
一个最简单的Web应用
新建一个maven项目
- 在pom文件中添加依赖
<!-- 添加spring boot父级依赖 -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
<relativePath />
</parent>
<!-- 添加 web支持的starter pom -->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<!-- 编译的插件 -->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
3.入口测试类
/**
* 入口类
*
* @author lizehao
* @2018年1月15日下午3:10:37
*/
@SpringBootApplication
public class Application {
/**
* 作为项目的入口
*/
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
4.编写控制器
@RestController
public class IndexController {
@RequestMapping("/")
public String index() {
return "the first example of spring boot";
}
}
5.直接运行main方法
浏览器输入: http://127.0.0.1:8080/