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

猜你喜欢

转载自blog.csdn.net/qq_24434061/article/details/83303830