Write micro service instance module, which is registered into the Eureka registry.
Add web pom.xml Eureka Client coordinate and end coordinate of SpringBoot
<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 configuration Eureka address micro-micro-service application name service instance name in the address 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
Write an interface
@Controller
public class TestController {
@ResponseBody
@RequestMapping(value="/test/{id}",method=RequestMethod.GET)
public String tet(@PathVariable("id") String id) {
return "8001"+id;
}
}
Add a new comment startup class
@EnableEurekaClient
Start Eureka, start micro service instance.