springcloud - alibaba快速上手 - 更新完毕
阅读原文时间:2021年12月07日阅读:1

3.1)、环境准备

  • 64 bit JDK 1.8 + ( 包括Window中的 和 Linux中的环境配置 ) linux-JDK8下载地址

  • Maven 3.2 + ( Window中的环境配置 )Maven下载地址

  • 下载nacos服务:官网地址

    • 注:要选择其他版本也可以,注意前面说的版本对应问题就行,我这里使用2.0.3,选这个版本对我后面的操作没影响

  • linux部署nacos服务

  • Window中启动不一样,其实早就会了的( 双击嘛 )

  • 经过如上的操作之后,就可以进入可视化页面了

4.1)、依赖

  • 父项目依赖管理

    <parent>
        <artifactId>spring-boot-parent</artifactId>
        <groupId>org.springframework.boot</groupId>
        <!-- 注意这里的版本问题 -->
        <version>2.3.12.RELEASE</version>
        <relativePath/>
    </parent>
  • 项目需要的依赖

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    &lt;dependency&gt;
        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
        &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
    &lt;/dependency&gt;
    
    &lt;!-- springcloud-alibaba需要的依赖 --&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;com.alibaba.cloud&lt;/groupId&gt;
        &lt;artifactId&gt;spring-cloud-starter-alibaba-nacos-discovery&lt;/artifactId&gt;
    &lt;/dependency&gt;
    </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Hoxton.SR12</version> <type>pom</type> <scope>import</scope> </dependency>
        &lt;dependency&gt;
            &lt;groupId&gt;com.alibaba.cloud&lt;/groupId&gt;
            &lt;artifactId&gt;spring-cloud-alibaba-dependencies&lt;/artifactId&gt;
            &lt;!-- 注意这里的版本问题 --&gt;
            &lt;version&gt;2.2.6.RELEASE&lt;/version&gt;
            &lt;type&gt;pom&lt;/type&gt;
            &lt;scope&gt;import&lt;/scope&gt;
        &lt;/dependency&gt;
    &lt;/dependencies&gt;
    </dependencyManagement>

4.2)、bootstrap.yml / application.yml配置

server:
  port: 8011

spring:
  application:
    name: ALIBABA-PUBLISHER
  cloud:
    nacos:
      discovery:
        server-addr: 162.14.66.60:8848  # 自己的服务器ip:8848

management:
  endpoints:
    web:
      exposure:
        include: "*" # 健康检查

4.3)、编写启动类 并 启动程序

package cn.zixieqing;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;

/**
 * @ClassName PublisherApplication
 * @Author ZiXieQing
 * @Date 2021/12/6
 * Version 1.0
 **/

@SpringBootApplication
@EnableDiscoveryClient      // 开启nacos的客户端功能
public class PublisherApplication {

    public static void main(String[] args) {

        SpringApplication.run(PublisherApplication.class, args);
    }
}

运行效果如下: