查看cloud和springboot的对应关系
查看cloud与alibaba的版本对应关系
组件版本对应关系
springboot、springcloud、springcloud-alibaba版本对应关系
64 bit JDK 1.8 + ( 包括Window中的 和 Linux中的环境配置 ) linux-JDK8下载地址
Maven 3.2 + ( Window中的环境配置 )Maven下载地址
下载nacos服务:官网地址
注:要选择其他版本也可以,注意前面说的版本对应问题就行,我这里使用2.0.3,选这个版本对我后面的操作没影响
linux部署nacos服务
Window中启动不一样,其实早就会了的( 双击嘛 )
经过如上的操作之后,就可以进入可视化页面了
初始化账户和密码:nacos和nacos
进去之后,就是如下样子,这里就是以后打交道的地方
父项目依赖管理
<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><dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<!-- springcloud-alibaba需要的依赖 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
</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> <dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<!-- 注意这里的版本问题 -->
<version>2.2.6.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
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: "*" # 健康检查
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);
}
}
运行效果如下:
手机扫一扫
移动阅读更方便
你可能感兴趣的文章