学习笔记:微服务-1.spring boot安装与hello world
数据越来越大,服务也越来越复杂,应用越来越彭大,为了提高应用服务的高稳定,高并发,高集群,高容错,低耦合,给出的新架构思维是把大的应用根据功能拆分成许多小的应用,分别开发,分别部署,通过各种大数据据集群的工具协同工作,就是分而自治,发展了一整套微服务的技术。spring是其中完整解决方案产品的提供者,spring cloud是微服务群的治理架构,spring boot是其中单个微服务的开发平台。
本节学习spring boot开发插件的安装和使用测试
1. 安装,Eclipse->帮助-》安装新软件-》增加
网址:http://download.springsource.com/release/TOOLS/update/e4.8
我的Eclipse是版本是4.9但 update/e4.9 网址总是安装错误,使用update/e4.8可正常安装
2.新建项目
文件-》新建-》其他-》Spring Boot->Spring Starter Project
下一步:
下一步:
3. 项目中新建一个类helloworld
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloWorld {
@RequestMapping("/")
public String helloworld(){
return "Hello World !spring Boot!";
}
}
4. 运行-》as ->Spring Boot App
可以看到在tomcat启动 8080端口服务
[ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
5. 打包成jar发布
有两种打包方式,一是打包成jar,单独运行,二是打包成war,发布到tomcat的webapps目录下
建议采用第一种,即打包成jar
运行-》调试方式-》maven clean
运行-》调试方式-》maven install
对话窗口需要指定运行时启动的类,即可打包成XXX.jar文件
运行 java -jar XXX.jar 然后可在浏览器访问服务
参考:
https://www.yiibai.com/spring-boot/ Spring Boot教程