标签:att lis dal type 9.png tab value service html
provider:
<properties> ...... <spring-cloud.version>Finchley.SR1</spring-cloud.version> </properties>
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-zookeeper-config</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-zookeeper-discovery</artifactId> </dependency> <dependency>
<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>
#http://cloud.spring.io/spring-cloud-static/Finchley.SR1/multi/multi_spring-cloud-zookeeper-config.html
spring:
cloud:
zookeeper:
discovery:
instancePort: ${server.port}
instanceHost: localhost
#enabled: true
#register: true
connectString: 192.168.1.186:2181,192.168.1.187:2181,192.168.1.188:2181
server.port=8080
spring.application.name=springcloud_zk
spring boot main class.
@EnableDiscoveryClient
package com.example.demo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; @SpringBootApplication @EnableDiscoveryClient //public class DemoApplication extends SpringBootServletInitializer { public class DemoApplication { // @Override // protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { // return application.sources(DemoApplication.class); // } public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } }
@Autowired private DiscoveryClient discoveryClient;
// https://stackoverflow.com/questions/45085790/spring-cloud-discoveryclient-getlocalserviceinstance-deprecated-how-to-use-r discoveryClient.getServices().forEach(id -> { discoveryClient.getInstances(id).forEach(instance -> { System.out.println("/listPage, host:" + instance.getHost() + ", " + "service_id:" + instance.getServiceId()); }); });
all code:
@RequestMapping(value = "/listPage", method = RequestMethod.GET) public String findAll(Model model) { List<UserDetails> users = userService.getUsers(); model.addAttribute("users", users); for(UserDetails user : users) { System.out.println(user.getEmail() + " " + user.getName()); } // https://stackoverflow.com/questions/45085790/spring-cloud-discoveryclient-getlocalserviceinstance-deprecated-how-to-use-r discoveryClient.getServices().forEach(id -> { discoveryClient.getInstances(id).forEach(instance -> { System.out.println("/listPage, host:" + instance.getHost() + ", " + "service_id:" + instance.getServiceId()); }); }); redisCliTest(); redisTest(); return "userList"; }
#zkCli.sh
>ls /services/springcloud_zk >get /services/springcloud_zk/[tab key]
http://localhost:8080/user/listPage
console:
/listPage, host:localhost, service_id:springcloud_zk
Reference:
1. 《SpringCloud之服务注册发现(Spring Cloud Zookeeper) |第十五章 -yellowcong》
标签:att lis dal type 9.png tab value service html
原文地址:https://www.cnblogs.com/xiaobin-hlj80/p/9823729.html