springboot
项目构建demo
@EnableDiscoveryClient
@EnableResourceServer
@SpringBootApplication
public class MerchantApplication {
public static void main(String[] args) {
SpringApplication.run(MerchantApplication.class, args);
}
}
在demo的resource下面创建.yml
spring:
application:
name: madmin
profiles:
active: default
cloud:
config:
enabled: true
uri: 指向config
# devtools:
# livereload:
# port: 35730
#debug: true
pom.xml 添加
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependency> 该jar包为eureka的连接
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-client</artifactId>
</dependency>
代码: 远程连接eureka的服务
@Autowired
private DiscoveryClient discoveryClient;
RestTemplate restTemplate = new RestTemplate();
List<ServiceInstance> instances =
discoveryClient.getInstances("admin");
if (instances.size() == 0)
return null;
log.info(XinyuanJSONUtil.gSonStringN(instances));
ServiceInstance t = instances.get(0);
String url = t.getUri()+"/"+t.getServiceId().toLowerCase();
log.info(url);
String serviceUri = String.format("地址",
url,id,loginType);
ResponseEntity<BaseResultDataDTO<Authorize>> restExchange =
restTemplate.exchange(serviceUri,HttpMethod.GET,null,new ParameterizedTypeReference<BaseResultDataDTO<Authorize>>(){},id,loginType);
BaseResultDataDTO<Authorize> authorize = restExchange.getBody();
log.info(XinyuanJSONUtil.gSonStringN(authorize));
return authorize.getData();
优质内容筛选与推荐>>1、DES加密算法介绍(含例子)
2、pygame save that Stream as video output.
3、转载 C#中敏捷开发规范
4、如何渡过中年危机(四条路:1.专注本业,做深做强 2.走架构 / 管理路线 3.转行到关联行业 4.创业开个公司,最考验综合能力。提前做好自己的职业规划)
5、Spring Cloud中,如何解决Feign/Ribbon第一次请求失败的问题?