设为首页 加入收藏

TOP

手把手教你将Eureka升级Nacos注册中心(一)
2023-07-26 08:17:14 】 浏览:79
Tags:Eureka 升级 Nacos

  由于原有SpringCloud体系版本比较老,最初的注册中心使用的Eureka后期官方无升级方案,配置中心无法在线管理配置,还有实时上下线的问题,因此需要将原有系统的Eureka服务升级Nacos注册心服务。

原有版本SpringBoot1.5.15、SpringCloud E、注册中心Eureka

升级后版本SpringBoot2.1.6、SpringCloud G、注册中心Nacos1.4.2

1.升级springboot为2.x

注释掉根目录下的parent,和starter依赖。

注释掉dependencyManagement下的platform-bom

 

 添加dependencyManagement的springboot依赖

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-dependencies</artifactId>
    <version>${spring-boot.version}</version>
    <type>pom</type>
    <scope>import</scope>
</dependency>

添加打包资源

 

<resources>
    <!--如果不设置resource 会导致application.yml中的@@找不到pom文件中的配置-->
    <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
    </resource>
</resources>

2.升级springcloud版本到Greenwich.SR2

并添加alibaba.cloud版本

<spring-cloud-alibaba.version>2.2.6.RELEASE</spring-cloud-alibaba.version>

3.替换掉Eureka注册中心与配置中心

使用Undertow 替换内置 Tomcat;

<!--使用Undertow 替换内置 Tomcat-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-undertow</artifactId>
</dependency>

添加Nacos配置:

<!--阿里巴巴 nacos 服务发现-->
<!--注册中心-->
<dependency>
   <groupId>com.alibaba.cloud</groupId>
   <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
   <version>${spring-cloud-alibaba.version}</version>
</dependency>
<!--配置中心-->
<dependency>
   <groupId>com.alibaba.cloud</groupId>
   <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
   <version>${spring-cloud-alibaba.version}</version>
</dependency>

 添加监控相关引用

<!--配置文件处理器-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-configuration-processor</artifactId>
    <optional>true</optional>
</dependency>
<!--监控-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

升级Feign引用

<!--声明式接口调用-->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>

 SpringbootApplication启动项中更新为

@EnableFeignClients
@EnableDiscoveryClient
@SpringBootApplication
public class JoinDerepeatApplication {

}

4.更改配置文件bootstrap.yml

根据自身服务更改下面内容,${nacos-namespace:}这种写法是为了运行时可以由外部环境变量传入,而不用更改配置重新打包发布。

server:
  port: 8123
  u
首页 上一页 1 2 3 下一页 尾页 1/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇动态代理-cglib分析 下一篇HashMap源码分析 (基于JDK1.8)

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目