在application.yml中使用时找不到Spring-boot eureka.datacenter属性

时间:2018-04-10 14:24:29

标签: spring-boot spring-cloud netflix-eureka

我正在创建spring-boot Eureka server和客户端微服务以在aws上部署。我已经读过教程,我必须在我的eureka.datacenter: cloud eureka服务器中定义application.yml,以便它知道它在aws上。但是当我尝试在我的application.yml文件中使用它时,我得到unknown property 'eureka.datacenter'。 我为eureka服务器提供的依赖关系。

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

            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-config</artifactId>
            </dependency>

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

        </dependencies>

我正在使用Spring boot 1.5.8.RELEASE和春云Edgware.SR1

eureka.datacenter属性是否包含在不同版本的spring cloud中?

application.yml

spring:
  application:
    name: eureka-svc

---
spring:
  profiles: localhost
server:
  port: 8761
eureka:
  instance:
    hostname: localhost
  client:   
    fetchRegistry: false
    register-with-eureka: false
    serviceUrl:
      defaultZone: http://localhost:8761/eureka
---
spring:
  profiles: aws
server:
  port: 8761 
eureka:
  instance:
    non-secure-port: ${server.port}
    environment: production
  client:
    region: region
    register-with-eureka: true
    fetchRegistry: true
    use-dns-for-fetching-service-urls: true
    eureka-server-d-n-s-name: dns-name
    eureka-server-port: 8761
    eureka-server-u-r-l-context: eureka
  server:
    a-w-s-access-id: access-id
    a-w-s-secret-key: aws-key
    binding-strategy: route53
    list-auto-scaling-groups-role-name: role-name

3 个答案:

答案 0 :(得分:0)

可能没有区别,但你可以尝试:

eureka.datacenter: cloud

而不是:

eureka.datacenter=cloud

答案 1 :(得分:0)

您是否必须将eureka.datacenter作为命令行属性传递?

Configuring Eureka

  

如果您在云环境中运行,则需要传入java命令行属性-Deureka.datacenter = cloud,以便Eureka客户端/服务器知道初始化特定于AWS云的信息。

答案 2 :(得分:0)

我正在按照

的说明进行操作

https://cloud.spring.io/spring-cloud-netflix/multi/multi__service_discovery_eureka_clients.html#_using_eureka_on_aws

@EnableEurekaServer
@SpringBootApplication
public class DiscoveryServiceApplication {

    public static void main(String[] args) {
        SpringApplication.run(DiscoveryServiceApplication.class, args);
    }

    @Bean
    @Profile("aws")
    public EurekaInstanceConfigBean eurekaInstanceConfig(InetUtils inetUtils) {
        EurekaInstanceConfigBean b = new EurekaInstanceConfigBean(inetUtils);
        AmazonInfo info = AmazonInfo.Builder.newBuilder().autoBuild("eureka");
        b.setDataCenterInfo(info);
        return b;
    }

}