spring boot 学习–01–springboot开始
什么是springboot
spring boot 是一个开箱即用,可以基本不用配置文件,直接用默认配置来进行项目开发的框架,并且springboot是自带服务器的框架
springboot的优势
- 配置少
- 部署简单
- 一注到底
- 自带容器(jetty,tomcat)
基本配置
springboot使用
- 检查java (java -version)版本,看看是否是jdk1.7及以上
- 查看maven(mvn -v) 版本,最好是maven3.2以上
开发第一个springboot应用
1. 创建pom.xml
pom.xml
```xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.study.spring</groupId>
<artifactId>boot-hello</artifactId>
<version>1.0.0</version>
<!-- springboot 父类,版本控制-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.RELEASE</version>
</parent>
<dependencies>
<!--web应用配置 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<!-- 可执行jar配置 -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
2.编写主类
package com.springboot.study;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* Springboot 启动类,一般启动类都放在最上层包,就是根路径包
*
* SpringBootApplication = (@Configuration,@EnableAutoConfiguration,@ComponentScan)
*
* RestController restful形式的控制器和 Controller作用一样
*
* @author like
*
*/
@RestController
@SpringBootApplication
public class App {
@RequestMapping("/")
String home() {
return "Hello World!";
}
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
3. 启动应用
直接启动main主类,右键RUN AS
启动界面
- 访问 http://localhost:8080/
结果
OK