Skip to content

redwolf2019/spring-boot-nacos-config-example-2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

步骤

  • 建立SpringBoot工程,并引入NACOS Config Client
      <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
            <version>0.9.0.RELEASE</version>
        </dependency>
  • application.properties替换为bootstrap.properties

  • 写入基本配置信息到bootstrap.properties

spring.cloud.nacos.config.enabled=true
spring.cloud.nacos.config.server-addr=${NACOS_CONFIG_ADDR:127.0.0.1:8848}
spring.cloud.nacos.config.prefix=example
spring.cloud.nacos.config.group=DEFAULT_GROUP
spring.cloud.nacos.config.file-extension=properties
spring.profiles.active=base
spring.application.name=nacos-config-example-2
example=hello world
  • 在NACOS上建立配置文件:example-base.properties

    • 在 Nacos Spring Cloud 中,dataId 的完整格式: ${prefix}-${spring.profile.active}.${file-extension}
  • 启动SpringBoot

引用

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages