1、父工程 pom 文件
true Hoxton.SR1 2.2.0.RELEASE org.springframework.cloud spring-cloud-dependencies${spring-cloud.version} pom import com.alibaba.cloud spring-cloud-alibaba-dependencies${com-alibaba-cloud.version} pom import
2、子工程 pom 文件
org.springframework.boot spring-boot-starter-webcom.alibaba.cloud spring-cloud-starter-alibaba-nacos-discoverycom.alibaba.cloud spring-cloud-starter-alibaba-nacos-configorg.springframework.boot spring-boot-starter-actuatororg.springframework.boot spring-boot-starter-testtest
3、新建 bootstrap.yml 文件
server:
port: 9001
spring:
application:
name: service-product
profiles:
active: dev
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848 # 注册中心地址
config:
server-addr: 127.0.0.1:8848 # 配置中心地址
file-extension: yaml # 文件后缀 默认 properties
# group: service-product # 主要针对业务
# namespace: 736e6c9d-e584-4cc9-857b-89c4bdbae841 # 读取哪个环境---区分环境
# enabled: true # 是否开启
management:
endpoints:
jmx:
exposure:
include: '*'
4、创建 测试 Controller
package com.wcc.serviceproduct.controller;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import java.util.concurrent.TimeUnit;
@RestController
public class TestController {
@Value("${server.port}")
private String port;
@Value("${person.name}")
private String name;
@GetMapping("/get/{str}")
public String get(@PathVariable("str") String str) throws InterruptedException {
// TimeUnit.SECONDS.sleep(2);
return port + "--------"+name+"-------" +str;
}
}
5、在 nacos 创建 配置文件
Data Id规则:${prefix}-${spring.profiles.active}.${file-extension} prefix 默认spring.application.name
6、 访问 http://127.0.0.1:9001/get/1



