1、Spring Boot简介
(1)、简化Spring应用开发的一个框架;
(2)、整个Spring技术栈的一个大整合;
2、Spring Boot HelloWorld
2.1 创建一个maven工程(jar)
2.2 导入依赖spring boot相关的依赖
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.12.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
2.3编写主程序
/**
* @SpringBootApplication来标注一个主程序类,说明这是一个SpringBoot应用
*/
@SpringBootApplication
public class HelloWorldMainApplication {
public static void main(String[] args) {
//Spring应用启动
SpringApplication.run(HelloWorldMainApplication.class, args);
}
}
2.4 编写相关的controller、service
@RestController
public class HelloController {
@RequestMapping("/hello")
public String hello(){
return "Hello world";
}
}
2.5 简化部署
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
使用maven打包命令将其打包成jar包后,直接使用命令:
java -jar xxx.jar
就能启动springboot项目啦
网友评论