什么是微服务:
martinfowler.com
编写helloword
创建一个maven工程:(jar) 不勾选
1 导入相关的依赖(不用导入tomcat服务器)
父项目依赖父项目,上面一级是springboot的依赖中心,所以导入版本之后是不需要写版本的.没有被管理的除外.
<textarea readonly="readonly" name="code" class="java">
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
2 编写主程序
@SpringBootApplication标注这是一个主程序类
<textarea readonly="readonly" name="code" class="java">
public static void main(String[] args) {
//Spring应用启动起来
SpringApplication.run(MainApplication.class,args);
}
3 编写controller
@RestController
4 打包成jar包的方式:(简化部署)
<textarea readonly="readonly" name="code" class="java">
<!--将应用打包成一个可以执行的jar包-->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
找到文件所在的目录然后直接cmd运行 Java -jar ***.jar
去Spring.io搜索starters可以看见更多的场景启动器,通过导入starters就可以使用相关的功能.