工作三年有接触过微服务的项目,但是因为种种原因浅尝辄止.
换工作后,开始恶补这方面的知识.尝试着自己搭建一套简单的spring-cloud项目
本着学习的想法,先搭一个基础工程,再一点点去学习细节
我是直接用ide创建的,
下一步,填写工程名称选择java版本
选择要使用的一些工具或者依赖吧,我这里什么都没有选择.因为我是想的搭建一个父工程.然后,去创建子工程
我的一个简单工程结构是这样的
org.springframework.cloud
spring-cloud-dependencies
Hoxton.RELEASE
pom
import
我的spring-boot-starter-parent的版本是 2.2.6.RELEASE 尝试启动,报错: Description: Your project setup is incompatible with our requirements due to following reasons: - Spring Boot [2.2.6.RELEASE] is not compatible with this Spring Cloud release train Action: Consider applying the following actions: - Change Spring Boot version to one of the following versions [2.6.x, 2.7.x] . You can find the latest Spring Boot versions here [https://spring.io/projects/spring-boot#learn]. If you want to learn more about the Spring Cloud Release train compatibility, you can visit this page [https://spring.io/projects/spring-cloud#overview] and check the [Release Trains] section. If you want to disable this check, just set the property [spring.cloud.compatibility-verifier.enabled=false]
根据提示信息把spring-boot-starter-parent版本切换为
2.7.4
再次启动,启动成功.
我写了个测试接口
package com.springcloud.demo.rest.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author
* @date 2022/9/24 下午3:01
*/
@RestController
@RequestMapping("/test")
public class TestController {
@GetMapping("/get/{str}")
private String get(@PathVariable("str") String str) {
return str;
}
}
访问没问题
我是参考公司项目进行搭建的系统, 我看公司的配置文件都是bootstrap.yml.不太明白为什么是这个.
百度了一下,找到一篇对我这个新手而言通俗易懂方便理解的
bootstrap.properties 和 application.properties的区别?_Modesty.P.Gao的博客-CSDN博客_application.properties和bootstrap
我的理解就是,像我这种只是引入了springcloud依赖的.可以暂时不用管这个.
但是如果要用bootstrap.yml做配置文件,并且使其生效的话.需要引入一个依赖.
3.1.3
结束!!!!!!
新手初学,不喜勿喷.后续会慢慢的一步步的去继承相关微服务组件进来