博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
springboot集成nacos
阅读量:2064 次
发布时间:2019-04-29

本文共 2480 字,大约阅读时间需要 8 分钟。

1.现在nacos进行配置添加

2.springboot项目集成nacos

nacos上有说明,根据不同的工程进行配置,如下图

集成nacos客户端包

com.alibaba.boot
nacos-config-spring-boot-starter
0.1.6

加载配置文件

/***MITLicense*Copyright(c)2018haihua.liu*Permissionisherebygranted,freeofcharge,toanypersonobtainingacopy*ofthissoftwareandassociateddocumentationfiles(the"Software"),todeal*intheSoftwarewithoutrestriction,includingwithoutlimitationtherights*touse,copy,modify,merge,publish,distribute,sublicense,and/orsell*copiesoftheSoftware,andtopermitpersonstowhomtheSoftwareis*furnishedtodoso,subjecttothefollowingconditions:*Theabovecopyrightnoticeandthispermissionnoticeshallbeincludedinall*copiesorsubstantialportionsoftheSoftware.*THESOFTWAREISPROVIDED"ASIS",WITHOUTWARRANTYOFANYKIND,EXPRESSOR*IMPLIED,INCLUDINGBUTNOTLIMITEDTOTHEWARRANTIESOFMERCHANTABILITY,*FITNESSFORAPARTICULARPURPOSEANDNONINFRINGEMENT.INNOEVENTSHALLTHE*AUTHORSORCOPYRIGHTHOLDERSBELIABLEFORANYCLAIM,DAMAGESOROTHER*LIABILITY,WHETHERINANACTIONOFCONTRACT,TORTOROTHERWISE,ARISINGFROM,*OUTOFORINCONNECTIONWITHTHESOFTWAREORTHEUSEOROTHERDEALINGSINTHE*SOFTWARE.*/packagecn.liuhaihua.web;importcn.liuhaihua.web.mapper.BaseMapper;importcom.alibaba.nacos.spring.context.annotation.config.NacosPropertySource;importorg.mybatis.spring.annotation.MapperScan;importorg.springframework.boot.SpringApplication;importorg.springframework.boot.autoconfigure.SpringBootApplication;importorg.springframework.boot.web.servlet.ServletComponentScan;importorg.springframework.transaction.annotation.EnableTransactionManagement;/***@ClassName:JWordpressWebApplication*@Description:Springboot应用程序启动类*@authorLiuhaihua*@date2018年6月26日**/@SpringBootApplication@ServletComponentScan@EnableTransactionManagement@MapperScan(basePackages="cn.liuhaihua.web.*",markerInterface=BaseMapper.class)@NacosPropertySource(dataId="web",autoRefreshed=true)publicclassJWordpressWebApplication{/***@Title:main*@Description:main启动方法*@param@paramargs*@returnvoid*@throws*/publicstaticvoidmain(String[]args){SpringApplication.run(JWordpressWebApplication.class,args);System.out.println("JWordpressWebApplication启动成功");}}

主要代码是:

@NacosPropertySource(dataId="web",autoRefreshed=true)

dataId="web" 对应的是你在nacos服务端的配置

如果要区分不同环境的话(开发/测试/生产)需要配上namespace,

application.properties

spring.profiles.active=develop

application-develop.properties

nacos.config.server-addr=10.42.226.203:8848nacos.config.namespace=39a58908-d8af-4816-b87d-c964aa8cbaf2

启动测试:

说明能加载到配置文件,成功

目前100000+人已关注加入我们

       

       

转载地址:http://bxwmf.baihongyu.com/

你可能感兴趣的文章
【Python】详解Python多线程Selenium跨浏览器测试
查看>>
Jmeter之参数化
查看>>
Shell 和Python的区别。
查看>>
Python 列表(list)、字典(dict)、字符串(string)常用基本操作小结
查看>>
Loadrunner之https协议录制回放报错如何解决?(九)
查看>>
python中xrange和range的异同
查看>>
列表、元组、集合、字典
查看>>
【Python】easygui小甲鱼
查看>>
【Python】关于Python多线程的一篇文章转载
查看>>
【Pyton】【小甲鱼】文件
查看>>
【Pyton】【小甲鱼】永久存储:腌制一缸美味的泡菜
查看>>
【Pyton】【小甲鱼】异常处理:你不可能总是对的
查看>>
APP性能测试工具
查看>>
【Pyton】【小甲鱼】类和对象
查看>>
压力测试工具JMeter入门教程
查看>>
作为一名软件测试工程师,需要具备哪些能力
查看>>
【Pyton】【小甲鱼】类和对象:一些相关的BIF(内置函数)
查看>>
【Pyton】【小甲鱼】魔法方法
查看>>
单元测试需要具备的技能和4大阶段的学习
查看>>
【Loadrunner】【浙江移动项目手写代码】代码备份
查看>>