1. 程式人生 > >SpringCloud的服務註冊中心

SpringCloud的服務註冊中心

服務註冊中心個人網址:

http://limenghua.xyz:1111/

建立一個springboot專案:

pom.xml檔案需引入的jar包

<dependencies>
   <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter</artifactId>
   </dependency>

   <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-eureka-server</artifactId>
   </dependency>
</dependencies>

 

應用上加上@EnableEurekaServer註解可以讓應用變為Eureka伺服器,這是因為spring boot封裝了Eureka Server,讓你可以嵌入到應用中直接使用。至於真正的EurekaServer是Netflix公司的開源專案,也是可以單獨下載使用的。

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@EnableEurekaServer
@SpringBootApplication
public class EurekaServerApplication {
    public static void main(String[] args) {
        SpringApplication.run(EurekaServerApplication.class, args);
    }
}

 

yml檔案配置:

server:
  port: 1111
eureka:
  instance.hostname: localhost
  client.register-with-eureka: false
  client.fetch-registry: false
  client.service-url.defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

 

如果使用properties檔案的話:

server.port=1111

eureka.instance.hostname=localhost

eureka.client.registerWithEureka=false

eureka.client.fetchRegistry=false

eureka.client.serviceUrl.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka/

 

yml檔案和properties的區別:

yml檔案的好處,天然的樹狀結構,一目瞭然,實質上跟properties是差不多的。

注意點:

1,原有的key,例如spring.jpa.properties.hibernate.dialect,按“.”分割,都變成樹狀的配置

2,key後面的冒號,後面一定要跟一個空格

3,把原有的application.properties刪掉。然後一定要執行一下  maven -X clean install

4,折行後的格式一定要正確.

 

關於pring Boot application.yml application.properties 優先順序

https://blog.csdn.net/testcs_dn/article/details/79010798