本文来自视频教程
-
Building Microservices with Spring Boot LiveLessons (Video Training)
-
http://www.infoq.com/cn/articles/microframeworks1-spring-boot
安装springcli
brew tap pivotal/tap ; brew install springboot
新建一个example.groovy
@RestController
public class Example {
@RequestMapping("/")
String hello() {
return "Hello World!"
}
}
执行启动:
spring run example.groovy
# 如果你想生成一个jar包
spring jar example.jar example.groovy
java -jar example.jar
打开浏览器 http://localhost:8080/
Hello World!
进去网站按需要添加依赖点击下载即可。http://start.spring.io/ 下载demo.tar,解压后是一个完整的maven工程
➜ d1 ls
mvnw mvnw.cmd pom.xml src target
添加代码
package com.example;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class ExampleController {
@RequestMapping("/")
public String hello () {
return "Hello Java World!";
}
}
打包
mvn clean package
运行
mvn spring-boot:run
或者基于软件如LVS
java -jar target/demo-0.0.1-SNAPSHOT.jar