springboot 통합 nacos 설정 방법
3884 단어 springbootnacos
nacos 창고:https://github.com/alibaba/nacos
nacos 소개 문서:https://nacos.io/zh-cn/docs/architecture.html
nacos 사용 예:https://github.com/nacos-group/nacos-examples
springboot 설정-통합 nacos,예 코드 다운로드
springboot-nacos-consumer
springboot-nacos
1.설치 정보
nacos-mysql.sql 가 져 오기
나 코스 콘 솔 시작
2.게시 및 가 져 오기 설정
1)발표 2 가지 방식 설정:openapi 호출;콘 솔 조작
2)새 네 임 스페이스
3)서로 다른 namespace,서로 다른 dataId,서로 다른 groupId 설정 가 져 오기
@NacosPropertySource 에 dataId,groupId 지정
// dataId example ,
//@NacosPropertySource(dataId = "example",autoRefreshed = true)
// groupId
//@NacosPropertySource(dataId = "example", groupId ="test",autoRefreshed = true)
// dataId
@NacosPropertySource(dataId = "example2",autoRefreshed = true)
프로필 에 namespace 를 지정 한 ID
# ID, namespace
#nacos.config.namespace=a8128f5b-7f87-42c5-9ffd-c4f17da7ee34
테스트:3.서비스 등록 및 소비 서비스
1)서비스 등록
프로필 지정:
server.port= 8080
#
server.context-path=/springboot-nacos
#Nacos
spring.application.name=UserService
#nacos
nacos.config.server-addr=127.0.0.1:8848
#discovery
nacos.discovery.server-addr=127.0.0.1:8848
# ID, namespace
#nacos.config.namespace=a8128f5b-7f87-42c5-9ffd-c4f17da7ee34
서비스 시작 시 등록:
@SpringBootApplication
public class SpringbootNacosApplication {
@NacosInjected
private NamingService namingService;
@Value("${server.port}")
private int serverPort;
@Value("${spring.application.name}")
private String applicationName;
//curl -X PUT 'http://127.0.0.1:8848/nacos/v1/ns/instance?serviceName=xxx&ip=127.0.0.1&port=8080'
@PostConstruct
public void registerInstance() throws NacosException {
if(CollectionUtils.isEmpty(namingService.getAllInstances(applicationName))){
namingService.registerInstance(applicationName,"127.0.0.1",serverPort);
}
}
public static void main(String[] args) {
SpringApplication.run(SpringbootNacosApplication.class, args);
}
}
2)서비스 소비
Naming Service 를 통 해 선택 서비스 발견
Instance instance = namingService.selectOneHealthyInstance("UserService");
RestTemplate 호출 을 통 해 결 과 를 가 져 옵 니 다.springboot 통합 nacos 의 설정 방법 에 관 한 이 글 은 여기까지 소개 되 었 습 니 다.더 많은 springboot 통합 nacos 내용 은 우리 의 이전 글 을 검색 하거나 아래 의 관련 글 을 계속 찾 아 보 세 요.앞으로 도 많은 응원 부 탁 드 리 겠 습 니 다!
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Kotlin Springboot -- 파트 14 사용 사례 REST로 전환하여 POST로 JSON으로 전환前回 前回 前回 記事 の は は で で で で で で を 使っ 使っ 使っ て て て て て リクエスト を を 受け取り 、 reqeustbody で 、 その リクエスト の ボディ ボディ を を 受け取り 、 関数 内部 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.