SpringCloud基础(1)-关于SpringCloud的基本了解与初始创建(2020年)

1. SpringCloud和SpringBoot的版本选择问题

在官方文档中对SpringBoot和SpringCloud的版本进行了规定,官方位置;也可以在浏览器中输入网址https://start.spring.io/actuator/info,将得到的json字符串放到在线JSON解析工具,一解析就可以看出结果,解析得到的数据如下;

{
	"git": {
		"branch": "ceb7d8739f1b3d841fd5f61630fefcb829c183eb",
		"commit": {
			"id": "ceb7d87",
			"time": "2020-12-11T13:37:01Z"
		}
	},
	"build": {
		"version": "0.0.1-SNAPSHOT",
		"artifact": "start-site",
		"versions": {
			"spring-boot": "2.4.1",
			"initializr": "0.10.0-SNAPSHOT"
		},
		"name": "start.spring.io website",
		"time": "2020-12-11T13:39:31.767Z",
		"group": "io.spring.start"
	},
	"bom-ranges": {
		"azure": {
			"2.0.10": "Spring Boot >=2.0.0.RELEASE and <2.1.0.RELEASE",
			"2.1.10": "Spring Boot >=2.1.0.RELEASE and <2.2.0.M1",
			"2.2.4": "Spring Boot >=2.2.0.M1 and <2.3.0.M1",
			"2.3.5": "Spring Boot >=2.3.0.M1"
		},
		"codecentric-spring-boot-admin": {
			"2.0.6": "Spring Boot >=2.0.0.M1 and <2.1.0.M1",
			"2.1.6": "Spring Boot >=2.1.0.M1 and <2.2.0.M1",
			"2.2.4": "Spring Boot >=2.2.0.M1 and <2.3.0.M1",
			"2.3.1": "Spring Boot >=2.3.0.M1 and <2.5.0-M1"
		},
		"solace-spring-boot": {
			"1.0.0": "Spring Boot >=2.2.0.RELEASE and <2.3.0.M1",
			"1.1.0": "Spring Boot >=2.3.0.M1 and <2.5.0-M1"
		},
		"solace-spring-cloud": {
			"1.0.0": "Spring Boot >=2.2.0.RELEASE and <2.3.0.M1",
			"1.1.1": "Spring Boot >=2.3.0.M1 and <2.5.0-M1"
		},
		"spring-cloud": {
			"Finchley.M2": "Spring Boot >=2.0.0.M3 and <2.0.0.M5",
			"Finchley.M3": "Spring Boot >=2.0.0.M5 and <=2.0.0.M5",
			"Finchley.M4": "Spring Boot >=2.0.0.M6 and <=2.0.0.M6",
			"Finchley.M5": "Spring Boot >=2.0.0.M7 and <=2.0.0.M7",
			"Finchley.M6": "Spring Boot >=2.0.0.RC1 and <=2.0.0.RC1",
			"Finchley.M7": "Spring Boot >=2.0.0.RC2 and <=2.0.0.RC2",
			"Finchley.M9": "Spring Boot >=2.0.0.RELEASE and <=2.0.0.RELEASE",
			"Finchley.RC1": "Spring Boot >=2.0.1.RELEASE and <2.0.2.RELEASE",
			"Finchley.RC2": "Spring Boot >=2.0.2.RELEASE and <2.0.3.RELEASE",
			"Finchley.SR4": "Spring Boot >=2.0.3.RELEASE and <2.0.999.BUILD-SNAPSHOT",
			"Finchley.BUILD-SNAPSHOT": "Spring Boot >=2.0.999.BUILD-SNAPSHOT and <2.1.0.M3",
			"Greenwich.M1": "Spring Boot >=2.1.0.M3 and <2.1.0.RELEASE",
			"Greenwich.SR6": "Spring Boot >=2.1.0.RELEASE and <2.1.999.BUILD-SNAPSHOT",
			"Greenwich.BUILD-SNAPSHOT": "Spring Boot >=2.1.999.BUILD-SNAPSHOT and <2.2.0.M4",
			"Hoxton.SR9": "Spring Boot >=2.2.0.M4 and <2.3.8.BUILD-SNAPSHOT",
			"Hoxton.BUILD-SNAPSHOT": "Spring Boot >=2.3.8.BUILD-SNAPSHOT and <2.4.0.M1",
			"2020.0.0-M3": "Spring Boot >=2.4.0.M1 and <=2.4.0.M1",
			"2020.0.0-M4": "Spring Boot >=2.4.0.M2 and <=2.4.0-M3",
			"2020.0.0-M6": "Spring Boot >=2.4.0.M4 and <2.4.2-SNAPSHOT",
			"2020.0.0-SNAPSHOT": "Spring Boot >=2.4.2-SNAPSHOT"
		},
		"spring-cloud-alibaba": {
			"2.2.1.RELEASE": "Spring Boot >=2.2.0.RELEASE and <2.3.0.M1"
		},
		"spring-cloud-gcp": {
			"2.0.0-RC2": "Spring Boot >=2.4.0-M1 and <2.5.0-M1"
		},
		"spring-cloud-services": {
			"2.0.3.RELEASE": "Spring Boot >=2.0.0.RELEASE and <2.1.0.RELEASE",
			"2.1.8.RELEASE": "Spring Boot >=2.1.0.RELEASE and <2.2.0.RELEASE",
			"2.2.6.RELEASE": "Spring Boot >=2.2.0.RELEASE and <2.3.0.RELEASE",
			"2.3.0.RELEASE": "Spring Boot >=2.3.0.RELEASE and <2.4.0-M1"
		},
		"spring-geode": {
			"1.2.12.RELEASE": "Spring Boot >=2.2.0.M5 and <2.3.0.M1",
			"1.3.7.RELEASE": "Spring Boot >=2.3.0.M1 and <2.4.0-M1",
			"1.4.0": "Spring Boot >=2.4.0-M1"
		},
		"spring-statemachine": {
			"2.0.0.M4": "Spring Boot >=2.0.0.RC1 and <=2.0.0.RC1",
			"2.0.0.M5": "Spring Boot >=2.0.0.RC2 and <=2.0.0.RC2",
			"2.0.1.RELEASE": "Spring Boot >=2.0.0.RELEASE"
		},
		"vaadin": {
			"10.0.17": "Spring Boot >=2.0.0.M1 and <2.1.0.M1",
			"14.4.4": "Spring Boot >=2.1.0.M1 and <2.5.0-M1"
		},
		"wavefront": {
			"2.0.2": "Spring Boot >=2.1.0.RELEASE and <2.4.0-M1",
			"2.1.0-SNAPSHOT": "Spring Boot >=2.4.0-M1"
		}
	},
	"dependency-ranges": {
		"okta": {
			"1.2.1": "Spring Boot >=2.1.2.RELEASE and <2.2.0.M1",
			"1.4.0": "Spring Boot >=2.2.0.M1 and <2.4.0-M1",
			"1.5.1": "Spring Boot >=2.4.0-M1 and <2.5.0-M1"
		},
		"mybatis": {
			"2.0.1": "Spring Boot >=2.0.0.RELEASE and <2.1.0.RELEASE",
			"2.1.4": "Spring Boot >=2.1.0.RELEASE and <2.5.0-M1"
		},
		"camel": {
			"2.22.4": "Spring Boot >=2.0.0.M1 and <2.1.0.M1",
			"2.25.2": "Spring Boot >=2.1.0.M1 and <2.2.0.M1",
			"3.3.0": "Spring Boot >=2.2.0.M1 and <2.3.0.M1",
			"3.5.0": "Spring Boot >=2.3.0.M1 and <2.4.0-M1"
		},
		"open-service-broker": {
			"2.1.3.RELEASE": "Spring Boot >=2.0.0.RELEASE and <2.1.0.M1",
			"3.0.4.RELEASE": "Spring Boot >=2.1.0.M1 and <2.2.0.M1",
			"3.1.1.RELEASE": "Spring Boot >=2.2.0.M1 and <2.4.0-M1"
		}
	}
}

然后选择一个比较稳定的SpringCloud,通过这个SpringCloud来确定其它工具的版本;


这一次选用的SpringCloud版本是Hoxton.SR9,SpringCloud版本是 2.3.5.RELEASE;

2. 基本创建

  1. 先创建一个Maven工程,这个Maven工程就是一个父类的工程组件,尤其是它的pom文件,可以被后面的子类工程来继承;
  2. 要明白约定>配置>编码,所以很多的东西,尤其是pom文件,yml配制,最好是有一套基本的模板作为规范;不然就自己按照自己的来,很容易出错,不过配置可能会相对少一点;
  3. 再然后就是编写基本的业务逻辑代码;
    大致这便是一个基本项目的创建套路,因为SpringCloud其实也是建立在SpringBoot项目之上的;

注意点

  1. 在父工程的pom.xml文件中,标签<packaging>的内容是pom。而且含有<dependencyManagement>,这个标签里面含有标签<dependencies>。而且所有子类工程都会沿用父类的版本号。
  2. <dependencyManagement>这个标签声明依赖,并不引用,所以子项目还是需要显示的引入项目。子项目只会取父项目的version和scope。
  3. 在Mybatis中使用的占位符时,如果传入的是字符型数据,那么使用#{}时会带有单引号,用来防止sql注入。如果使用${}是不带有单引号的。如此而言,简而言之,就是说如果是条件的话,那么就最好使用#{},如果是查询的结果和表就需要使用${}
  4. 注解@Autowired和@Resource都可以用来注入bean依赖对象,就是通过Bean注解或者<Bean>创建的一些对象。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

神秘的天

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值