springcloud alibaba-生产者模块注册到nacos

  1. 创建生产者模块

  2. 添加依赖;依赖得添加两个地方:一个父pom,一个是本模块pom

            <!--spring cloud 阿里巴巴--> //父pom
            <dependency>
                <groupId>com.alibaba.cloud</groupId>
                <artifactId>spring-cloud-alibaba-dependencies</artifactId>
                <version>2.1.0.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        <!--  SpringCloud alibaba nacos    -->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        </dependency>

  3. 添加配置

server:
  port: 9001
spring:
  application:
    name: nacos-payment-provider
  cloud:
    nacos:
      discovery:
        server-addr: localhost:8848

management: #暴露监控端点,用于被监控
  endpoints:
    web:
      exposure:
        include: "*"

  4. 主启动

@SpringBootApplication
@EnableDiscoveryClient
public class NacosProviderApplication {

    public static void main(String[] args) {
        SpringApplication.run(NacosProviderApplication.class, args);
    }
}

  5. 业务类(略)

  6. 测试:访问 http://localhost:8848/nacos

  总结下:nacos比较友好,有 注册中心的服务器和后台界面提供,只需要服务模块到上面注册即可。

posted @ 2021-02-27 13:33  爱编程DE文兄  阅读(135)  评论(0编辑  收藏  举报