nacos 服务搭建

nacos的服务搭建

首先我们需要一个nacos的jar包

nacos 服务搭建_第1张图片
在bin目录下执行 startup.cmd -m standalone

依赖
   
        <dependency>
            <groupId>com.alibaba.cloudgroupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-configartifactId>
        dependency>
        
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-webartifactId>
        dependency>

        
        <dependency>
            <groupId>com.alibaba.cloudgroupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discoveryartifactId>
        dependency>

nacos视图化操作面板

nacos 服务搭建_第2张图片
nacos 服务搭建_第3张图片

父项目的依赖

<properties>
    
    <java.version>1.8java.version>
    <project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8project.reporting.outputEncoding>

    
    <spring-cloud.version>Hoxton.SR3spring-cloud.version>
    <spring-cloud-alibaba.version>2.2.1.RELEASEspring-cloud-alibaba.version>
  properties>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.springframework.cloudgroupId>
        <artifactId>spring-cloud-dependenciesartifactId>
        <version>${spring-cloud.version}version>
        <type>pomtype>
        <scope>importscope>
      dependency>
      <dependency>
        <groupId>com.alibaba.cloudgroupId>
        <artifactId>spring-cloud-alibaba-dependenciesartifactId>
        <version>${spring-cloud-alibaba.version}version>
        <type>pomtype>
        <scope>importscope>
      dependency>
    dependencies>
  dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>junitgroupId>
      <artifactId>junitartifactId>
    dependency>
  dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.springframework.bootgroupId>
        <artifactId>spring-boot-maven-pluginartifactId>
        <version>2.4.5version>
      plugin>
    plugins>
  build>

idea中创建了一个bootstrap.yml的配置文件

server:
port: 8081
spring:
application:
  name: server-total
profiles:
  active: dev #环境变更
cloud:
  nacos:
    discovery:
      server-addr: localhost:8848 #Nacos地址
      #命名空间ID
      namespace: 14af447f-3f38-4189-9ea7-1d6faf303829
    config:
      server-addr: localhost:8848 #Nacos地址 可以不加 默认路径是上面的
      file-extension: yml #这里我们获取的properties格式的配置
      #命名空间ID
      namespace: 14af447f-3f38-4189-9ea7-1d6faf303829

到这里就可以使用了

你可能感兴趣的:(java后端,java)