org.springframework.cloud
spring-cloud-alibaba-dependencies
0.2.0.RELEASE
pom
import
org.springframework.cloud
spring-cloud-dependencies
Hoxton.SR12
pom
import
org.springframework.boot
spring-boot-dependencies
2.3.12.RELEASE
pom
import
2、建立子工程
=======
注意:同样是Maven。
3、搭建服务端springcloud-config-server-3344
=====================================
3.1 建立以下目录
3.2 导入依赖
org.springframework.cloud
spring-cloud-config-server
2.1.1.RELEASE
org.springframework.boot
spring-boot-starter-web
2.4.5
3.3 编写配置文件
server:
port: 3344
spring:
application:
name: springcloud-config-server
#连接远程仓库
cloud:
config:
server:
git:
uri: https://gitee.com/half-a-coke/springcloud-yixin-config.git
分析: uri的路径就是我们Git仓库中的http地址,如下图:
3.4 编写启动类
注意:要添加注解@EnableConfigServer,开启Config服务。
package com.yixin.springcloud;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;
@SpringBootApplication
@EnableConfigServer
public class Config_Server_3344 {
public static void main(String[] args) {
SpringApplication.run(Config_Server_3344.class,args);
}
}
3.5 测试
我们去看下我们仓库下的文件:
发现这里有我们自己添加的文件application.yml
查看application.yml的内容:
spring:
profiles:
active: dev
spring:
profiles: dev
application:
name: springcloud-config-dev
spring:
profiles: test
application:
name: springcloud-config-test
现在我们要通过远程访问这个配置文件:
访问:http://localhost:3344/application-test.yml
意思是访问拿到文件为application下profiles为test的信息。
可以发现成功拿到信息了,由于我们在配置文件中激活的是dev环境,所以这里active显示的是被激活环境的名字。
访问:http://localhost:3344/application-dev.yml
而且我们的访问格式也是可以有多种:
/{
application}/{
profile}[/{
label}]
label:代表我们仓库的分支。
例如:
访问:http://localhost:3344/application/dev/master
/{
application}-{
profile}.yml
访问:http://localhost:3344/application-dev.yml
/{
label}/{
application}-{
profile}.yml
访问:http://localhost:3344/master/application-dev.yml
同理对于properties文件也有以下几种
/{
application}-{
profile}.properties
/{
label}/{
application}-{
profile}.properties
4、搭建客户端springcloud-config-client
================================
4.1 准备工作
(1)编写一个config-client.yml添加到我们的远程仓库中
config-client.yml:
spring:
profiles:
active: dev
server:
port: 8201
spring:
profiles: dev
application:
name: springcloud-provider-blog
eureka:
client:
service-url:
defaultZone: http://localhost:7001/eureka/
server:
port: 8202
spring:
profiles: test
application:
name: springcloud-provider-blog
eureka:
client:
service-url:
defaultZone: http://localhost:7001/eureka/
(2)上传到远程仓库
在指定文件夹打开Git窗口
依次输入以下命令
cd 文件所在文件夹
添加
git add .
查看是否添加成功
git status
提交到本地
git commit -m “提交信息”
提交到远程仓库
git push origin master
查看仓库是否有我们的文件:
4.2 建立目录
4.3 导入依赖
org.springframework.cloud
spring-cloud-starter-config
2.1.1.RELEASE
org.springframework.boot
spring-boot-starter-web
2.4.5
4.4 编写配置文件
application.yml:
#用户级配置application
spring:
application:
name: springcloud-config-client-3355
bootstrap.yml:
#系统级配置bootstrap
spring:
cloud:
config:
#http://localhost:3344/config-client-dev/master
uri: http://localhost:3344
name: config-client
profile: dev
label: master
分析:
bootstrap.yml 是系统级别的配置
application.yml 是用户级别的配置
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数Java工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年Java开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Java开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
如果你觉得这些内容对你有帮助,可以扫码获取!!(备注Java获取)
最后
光给面试题不给答案不是我的风格。这里面的面试题也只是凤毛麟角,还有答案的话会极大的增加文章的篇幅,减少文章的可读性
Java面试宝典2021版
最常见Java面试题解析(2021最新版)
2021企业Java面试题精选
《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!
里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!**
如果你觉得这些内容对你有帮助,可以扫码获取!!(备注Java获取)
最后
光给面试题不给答案不是我的风格。这里面的面试题也只是凤毛麟角,还有答案的话会极大的增加文章的篇幅,减少文章的可读性
Java面试宝典2021版
[外链图片转存中…(img-Phsz8po3-1713393866562)]
[外链图片转存中…(img-xLKsww2U-1713393866562)]
最常见Java面试题解析(2021最新版)
[外链图片转存中…(img-c9nKUihr-1713393866563)]
[外链图片转存中…(img-RG1O3zID-1713393866563)]
2021企业Java面试题精选
[外链图片转存中…(img-YZ71M0Mn-1713393866563)]
[外链图片转存中…(img-4aOVQ43f-1713393866564)]
《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!