eureka学习(二)
eureka服务端创建好后,现在我们让eureka客户端(也就是服务提供者)注册到eureka上去。
首先加入依赖包:
<!--将微服务provider注册到eureka--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-config</artifactId> </dependency>
<!--保证info信息可以显示主管监控和信息配置-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<build>
<finalName>microservicecloud</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<delimiters>
<delimit>$</delimit>
</delimiters>
</configuration>
</plugin>
</plugins>
</build>
yml文件里加入eureka服务端的地址:
spring:
application:
name: microservicecloud #此为微服务的名称,注册到eureka时APPLICATIOIN处显示的就是这个,集群时此名称要一致
eureka: client: service-url: defaultZone: http://localhost:7001/eureka
instance:
instance-id: microservicecloud #些处注册到eureka上时,status处显示的名称,看下图中黑圈处
prefer-ip-address: true #此处为放在eureka中status上时显示ip
info:
app.name: microservicecloud-test
company.name: person
build.artifactId: $project.artifactId$
build.version: $project.version$
启动类里面加入@EnableEurekaClient
@SpringBootApplication @EnableEurekaClient //eureka客户端,启动后自动注册到服务端 public class ServerProvider { public static void main(String[] args) { SpringApplication.run(ServerProvider.class, args); } }
上图中,我图黑圈那里,显示的为本地localhost,与上面对应。
...