依赖
1 2 |
// https://mvnrepository.com/artifact/com.alibaba.boot/nacos-config-spring-boot-starter implementation group: 'com.alibaba.boot', name: 'nacos-config-spring-boot-starter', version: '0.2.12' |
配置文件 application.yml
1 2 3 4 5 |
nacos: config: server-addr: 127.0.0.1:8848 username: xxxx password: xxxxxx |
注解 @NacosPropertySource
1 2 3 4 5 6 7 8 9 10 |
@SpringBootApplication @MapperScan("com.w3cnet.xxx.repository") @NacosPropertySource(dataId = "xxx-prod.yml", autoRefreshed = true) public class XxxxApplication { public static void main(String[] args) { SpringApplication.run(XxxxApplication.class, args); } } |
注解 @NacosValue
1 2 |
@NacosValue(value = "${xxx.url}", autoRefreshed = true) private String xxxUrl; |
参考资料:https://nacos.io/zh-cn/docs/quick-start-spring-boot.html
View Details
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
docker run \ --name nacos -d \ -p 8848:8848 \ -p 9848:9848 \ -p 9849:9849 \ --privileged=true \ --restart=always \ -e JVM_XMS=256m \ -e JVM_XMX=256m \ -e MODE=standalone \ -e NACOS_AUTH_ENABLE=true \ -e NACOS_AUTH_TOKEN=n5zev798cgz0rn10andd85yrexre1u3f43gime523mrri7qc1pvwsxwipw1y \ -e NACOS_AUTH_IDENTITY_KEY=nacos \ -e NACOS_AUTH_IDENTITY_VALUE=xm4y03pc4lud5u0zu2tfpilkgqin6lwljlplcry893vtwdsw4a93r7f5nep3 \ -e PREFER_HOST_MODE=hostname \ -e SPRING_DATASOURCE_PLATFORM=mysql \ -e MYSQL_SERVICE_HOST=192.168.1.3 \ -e MYSQL_SERVICE_PORT=3306 \ -e MYSQL_SERVICE_USER=xxxx \ -e MYSQL_SERVICE_PASSWORD=xxxx \ -e MYSQL_SERVICE_DB_NAME=nacos_config \ -v /data/nacos/logs:/etc/nacos/logs \ -v /data/nacos/init.d/custom.properties:/etc/nacos/init.d/custom.properties \ nacos/nacos-server:latest |
View Details