当前位置: 首页 > news >正文

友情链接是在网站后台做吗市场营销专业

友情链接是在网站后台做吗,市场营销专业,建购物网站需要多少钱,wordpress小程序测试💗wei_shuo的个人主页 💫wei_shuo的学习社区 🌐Hello World ! Spring Cloud Eureka:服务注册与发现 Spring Cloud Eureka是Spring Cloud生态系统中的一个组件,它是用于实现服务注册与发现的服务治理组件。在…

在这里插入图片描述

💗wei_shuo的个人主页

💫wei_shuo的学习社区

🌐Hello World !


Spring Cloud Eureka:服务注册与发现

Spring Cloud Eureka是Spring Cloud生态系统中的一个组件,它是用于实现服务注册与发现的服务治理组件。在微服务架构中,服务之间存在复杂的依赖关系,而Spring Cloud Eureka可以帮助解决服务之间相互查找和通信的问题

Eureka简介

Eureka是Netflix开源的服务发现组件,用于在分布式系统中实现服务注册与发现。它是Netflix公司在构建微服务架构时开发的核心组件之一,后来成为了Spring Cloud生态系统中的一部分

Eureka注册中心搭建

Eureka服务端搭建

  • eureka-server依赖导入
<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
  • 启动类添加注解@EnableEurekaServer
@EnableEurekaServer
@SpringBootApplication
public class EurekaServerApplication {public static void main(String[] args) {SpringApplication.run(EurekaServerApplication.class, args);}
}
  • 配置文件application.yml配置
server:port: 8001 #指定运行端口
spring:application:name: eureka-server #指定服务名称
eureka:instance:hostname: localhost #指定主机地址client:fetch-registry: false #指定是否要从注册中心获取服务(注册中心不需要开启)register-with-eureka: false #指定是否要注册到注册中心(注册中心不需要开启)server:enable-self-preservation: false #关闭保护模式

Eureka客户端搭建

  • eureka-client依赖导入
<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId>
</dependency>
  • 启动类添加注解@EnableDiscoveryClient
@EnableDiscoveryClient
@SpringBootApplication
public class EurekaClientApplication {public static void main(String[] args) {SpringApplication.run(EurekaClientApplication.class, args);}
}
  • 配置文件application.yml配置
server:port: 8101 #运行端口号
spring:application:name: eureka-client #服务名称
eureka:client:register-with-eureka: true #注册到Eureka的注册中心fetch-registry: true #获取注册实例列表service-url:defaultZone: http://localhost:8001/eureka/ #配置注册中心地址

Eureka集群搭建

  • eureka-sever添加配置文件application-replica1.yml配置第一个注册中心
server:port: 8002
spring:application:name: eureka-server
eureka:instance:hostname: replica1client:serviceUrl:defaultZone: http://replica2:8003/eureka/ #注册到另一个Eureka注册中心fetch-registry: trueregister-with-eureka: true
  • 给eureka-sever添加配置文件application-replica2.yml配置第二个注册中心
server:port: 8003
spring:application:name: eureka-server
eureka:instance:hostname: replica2client:serviceUrl:defaultZone: http://replica1:8002/eureka/ #注册到另一个Eureka注册中心fetch-registry: trueregister-with-eureka: true
  • 修改Eureka-client,连接到集群
server:port: 8102
spring:application:name: eureka-client
eureka:client:register-with-eureka: truefetch-registry: trueservice-url:defaultZone: http://replica1:8002/eureka/,http://replica2:8003/eureka/ #同时注册到两个注册中心

Eureka添加认证

  • 添加SpringSecurity依赖
<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-security</artifactId>
</dependency>
  • 添加application.yml配置文件(配置用户名、密码)
server:port: 8004
spring:application:name: eureka-security-serversecurity: #配置SpringSecurity登录用户名和密码user:name: macropassword: 123456
eureka:instance:hostname: localhostclient:fetch-registry: falseregister-with-eureka: false

添加 Java 配置WebSecurityConfig


默认情况下,Spring Security会开启CSRF(Cross-Site Request Forgery)保护,这是一种用于防止跨站点请求伪造攻击的安全机制。当你添加了Spring Security依赖到应用程序中时,每个POST、PUT、DELETE等修改类请求都需要在请求头中包含CSRF token才能被服务器接受


默认情况下添加SpringSecurity依赖的应用每个请求都需要添加CSRF token才能访问,Eureka客户端注册时并不会添加,所以需要配置/eureka/**路径不需要CSRF token

@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {@Overrideprotected void configure(HttpSecurity http) throws Exception {http.csrf().ignoringAntMatchers("/eureka/**");super.configure(http);}
}

🌼 结语:创作不易,如果觉得博主的文章赏心悦目,还请——点赞👍收藏⭐️评论📝


在这里插入图片描述

http://www.hkea.cn/news/520235/

相关文章:

  • 青岛网站建设公司排行外链工具在线
  • 网站怎么做显得简洁美观seo数据是什么意思
  • 阿里巴巴开通诚信通后网站怎么做网络优化网站
  • 东莞手机网站价格便宜个人免费建站软件
  • 电子商务网站建设的步骤一般为百度100%秒收录
  • 做企业网站怎么样免费的推广软件下载
  • 拓普网站建设美国搜索引擎
  • 网站开发者工资冯耀宗seo视频教程
  • 软件开发各阶段工作量比例搜索引擎优化的基础是什么
  • 网站怎么做才能将名声打响云搜索app
  • 南阳做网站优化哪家好一级域名生成二级域名
  • 3322动态域名官网郑州seo联系搜点网络效果好
  • 网络营销渠道的类型河北seo基础教程
  • 做微信网站多少钱seo内部优化包括哪些内容
  • 中国城乡建设网站网络优化公司排名
  • 个人网站做淘宝客教程torrentkitty磁力搜索引擎
  • 广州北京网站建设seo培训讲师招聘
  • 手机上免费自己做网站网络营销案例分享
  • 长沙大型网站建设谷歌账号
  • 大兴德艺网站建设发布悬赏任务的推广平台
  • html5制作网站模板百度产品大全首页
  • 贵阳网站建设贵阳百度推广怎么推广
  • 瓮安建设局网站google play三件套
  • 大型门户网站模板营销神器
  • 学设计的网站都有哪些seo和sem
  • 如何做网站流量买卖营销型网站的特点
  • 装修设计网站哪个平台最好软文推广多少钱一篇
  • 怎么做微信里的网页网站链接网站设计平台
  • 长宁专业做网站网络营销案例分享
  • 哈尔滨专业建网站哪家好码迷seo