应用平台 APPSTAGE-使用Cloud Map SDK(Spring Cloud框架):初始化Cloud Map

时间:2024-10-21 16:40:47

初始化Cloud Map

在启动类中增加@EnableDiscoveryClient注解,同时在启动类中完成将RestTemplate放到spring容器中,后续微服务间调用就使用注册到spring容器中的RestTemplate,代码如下:

package com.huawei.demo.servicea;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

import com.huawei.wisesecurity.sts.springboot.security.annotation.EnableStsAutoInitialization;

@SpringBootApplication
@EnableStsAutoInitialization(value = "application.properties")
@EnableDiscoveryClient
public class ServiceASpringbootApplication {
    public static void main(String[] args) {
        SpringApplication.run(ServiceASpringbootApplication.class, args);
    }

    @Bean
    @LoadBalanced
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }
}
support.huaweicloud.com/sdkreference-appstage/appstage_08_0007.html