栏目分类:
子分类:
返回
终身学习网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
终身学习网 > IT > 软件开发 > 后端开发 > Java

springCloud+nacos微服务搭建

Java 更新时间:发布时间: 百科书网 趣学号
springCloud+nacos微服务搭建 1、创建项目

用户服务:muu-admin
商品服务:muu-commodity
公共服务:muu-common
网关:muu-gateway

1、Spring Initializr

2、model模块右击(创建各模块)

muu-admin、muu-commodity 模块勾选Web-String Web、SpringCloudRouting-OpenFeign
muu-gateway 模块勾选Web-String Web、SpringCloudRouting-Gateway

目录结构

2、处理pom依赖

父pom别忘了加入pom,不然打包失败。



    4.0.0
    pom
    
        org.springframework.boot
        spring-boot-starter-parent
        2.2.6.RELEASE
         
    
1、修改parent

修改每个模块parent全部引用父模块

2、各模块全部交给父工程管理

3、提取公共版本

所有子pom里的dependencyManagement移动到父pom,交给父pom管理。

3、启动nacos 1、引入nacos依赖

        
            com.alibaba.cloud
            spring-cloud-starter-alibaba-nacos-discovery
            ${alibaba-nacos-discovery.version}
        

公共服务引入,然后其他模块引入公共服务就可以了

2、启动类加上@EnableDiscoveryClient

需要注册nacos的启动类上加上@EnableDiscoveryClient注解

package com.mz.gateway;

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


@EnableDiscoveryClient
@SpringBootApplication
public class MuuGatewayApplication {

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

}
3、配置yml文件
server:
  port: 8000

spring:
  cloud:
    nacos:
      discovery:
        server-addr: 10.2.26.52:8848
        group: mz
        namespace: mz-muu

  application:
    name: muu-admin

4、起飞项目

nacos客户端下载地址https://github.com/alibaba/nacos/releases

转载请注明:文章转载自 www.051e.com
本文地址:http://www.051e.com/it/602627.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 ©2023-2025 051e.com

ICP备案号:京ICP备12030808号