一.基本信息
源码仓库:https://github.com/spring-projects/spring-boot
帮助文档:https://spring.io/guides/gs/spring-boot/
二.快速开始
1.通过maven创建一个工程
mvn archetype:generate -DgroupId=com.hippo -DartifactId=AppDemo -DarchetypeArtifactId=maven-archetype-webapp
2.创建一个package包目录
mkdir -p src/main/java/hello
3.配置一下pom.xml
4.0.0 com.hippo AppDemo 0.1.0 org.springframework.boot spring-boot-starter-parent 1.5.8.RELEASE org.springframework.boot spring-boot-starter-web 1.8 org.springframework.boot spring-boot-maven-plugin
4.创建一个contrller文件
touch src/main/java/hello/HelloController.java
package hello;import org.springframework.web.bind.annotation.RestController;import org.springframework.web.bind.annotation.RequestMapping;@RestControllerpublic class HelloController { @RequestMapping("/") public String index() { return "Greetings from Spring Boot!"; }}
5. 创建一个Application 启动文件
touch src/main/java/hello/Application.java
package hello;import java.util.Arrays;import org.springframework.boot.CommandLineRunner;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.context.ApplicationContext;import org.springframework.context.annotation.Bean;@SpringBootApplicationpublic class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } }
6.启动
mvn package && java -jar target/AppDemo.jar
7.访问
$ curl localhost:8080Greetings from Spring Boot!