SpringCloud---SpringCloud Eureka(二)

编写微服务实例module,将其注册进Eureka注册中心。

        pom.xml添加Eureka Client端坐标和SpringBoot的web坐标

<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-starter-eureka</artifactId>
 </dependency>
 <dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-web</artifactId>
 </dependency>

        application.properties配置Eureka地址 微服务应用名称 微服务在Eureka地址的实例名称

server.port=8001
spring.application.name=MicroService

#Eureka地址
eureka.client.service-url.defaultZone=http://localhost:7001/eureka/
#此微服务在Eureka地址的实例名称
eureka.instance.instance-id=Service
#是否显示此微服务的服务器ip地址
eureka.instance.prefer-ip-address=true

       编写一个接口

@Controller
public class TestController {
	
	@ResponseBody
	@RequestMapping(value="/test/{id}",method=RequestMethod.GET)
	public String tet(@PathVariable("id") String id) {
		return "8001"+id;
	}
	
}

      启动类添加新注解

@EnableEurekaClient

启动Eureka,在启动微服务实例。

扫描二维码关注公众号,回复: 9573244 查看本文章
发布了66 篇原创文章 · 获赞 26 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/qq_39115469/article/details/104650197