簡體   English   中英

無法從bootstrap.yml讀取配置服務器uri

[英]Can't read config server uri from bootstrap.yml

我正在嘗試使用以下pom創建一個eureka服務器注冊表以連接到配置服務器,但它無法連接配置服務器,因為它無法從bootstrap.yml文件中讀取正確的配置服務器uri;

 <parent>
    <groupId>xxx</groupId>
    <artifactId>yyy</artifactId>
    <version>1.0.0-SNAPSHOT</version>
  </parent>
  <modelVersion>4.0.0</modelVersion>

  <artifactId>cloudregistryapp</artifactId>
  <version>1.0.0-SNAPSHOT</version>

  <dependencies>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-config</artifactId>
      <version>2.1.2.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
      <version>2.1.1.RELEASE</version>
      <exclusions>
        <exclusion>
          <groupId>javax.servlet</groupId>
          <artifactId>servlet-api</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

我不得不排除servlet-api,但這是另一個主題。 在我的父pom(這是另一個maven模塊);

 <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.5.RELEASE</version>
    <relativePath/>
  </parent>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-dependencies</artifactId>
        <version>Greenwich.RELEASE</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>

這是app / resources目錄中的bootstrap.yml ;

spring:
  application:
    name: cloudregistry
  cloud:
    config:
      fail-fast: true
      uri: http://localhost:8080

eureka:
  instance:
    prefer-ip-address: true
  client:
    registerWithEureka: false
    fetchRegistry: false
    server:
      waitTimeInMsWhenSyancEmpty: 0

我期待看到嘗試連接到localhost:8080 for config server。 但是它吐出了以下輸出;

2019-06-18 14:52:02.701 DEBUG 32228 --- [           main] .c.l.ClasspathLoggingApplicationListener : Application started with classpath: unknown
2019-06-18 14:52:02.929 DEBUG 32228 --- [           main] o.s.boot.SpringApplication               : Loading source class org.springframework.cloud.bootstrap.BootstrapImportSelectorConfiguration
2019-06-18 14:52:03.312  INFO 32228 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$91d1cbee] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-06-18 14:52:03.411 DEBUG 32228 --- [           main] ConditionEvaluationReportLoggingListener : 


============================
CONDITIONS EVALUATION REPORT
============================


Positive matches:
-----------------

   ConfigServiceBootstrapConfiguration#configServicePropertySource matched:
      - @ConditionalOnProperty (spring.cloud.config.enabled) matched (OnPropertyCondition)
      - @ConditionalOnMissingBean (types: org.springframework.cloud.config.client.ConfigServicePropertySourceLocator; SearchStrategy: all) did not find any beans (OnBeanCondition)

   ConfigurationPropertiesRebinderAutoConfiguration matched:
      - @ConditionalOnBean (types: org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor; SearchStrategy: all) found bean 'org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor' (OnBeanCondition)

   ConfigurationPropertiesRebinderAutoConfiguration#configurationPropertiesBeans matched:
      - @ConditionalOnMissingBean (types: org.springframework.cloud.context.properties.ConfigurationPropertiesBeans; SearchStrategy: current) did not find any beans (OnBeanCondition)

   ConfigurationPropertiesRebinderAutoConfiguration#configurationPropertiesRebinder matched:
      - @ConditionalOnMissingBean (types: org.springframework.cloud.context.properties.ConfigurationPropertiesRebinder; SearchStrategy: current) did not find any beans (OnBeanCondition)

   EncryptionBootstrapConfiguration matched:
      - @ConditionalOnClass found required class 'org.springframework.security.crypto.encrypt.TextEncryptor' (OnClassCondition)

   PropertyPlaceholderAutoConfiguration#propertySourcesPlaceholderConfigurer matched:
      - @ConditionalOnMissingBean (types: org.springframework.context.support.PropertySourcesPlaceholderConfigurer; SearchStrategy: current) did not find any beans (OnBeanCondition)


Negative matches:
-----------------

   ConfigServiceBootstrapConfiguration.RetryConfiguration:
      Did not match:
         - @ConditionalOnClass did not find required class 'org.springframework.retry.annotation.Retryable' (OnClassCondition)

   DiscoveryClientConfigServiceBootstrapConfiguration:
      Did not match:
         - @ConditionalOnProperty (spring.cloud.config.discovery.enabled) did not find property 'spring.cloud.config.discovery.enabled' (OnPropertyCondition)

   EncryptionBootstrapConfiguration.RsaEncryptionConfiguration:
      Did not match:
         - Keystore nor key found in Environment (EncryptionBootstrapConfiguration.KeyCondition)
      Matched:
         - @ConditionalOnClass found required class 'org.springframework.security.rsa.crypto.RsaSecretEncryptor' (OnClassCondition)

   EncryptionBootstrapConfiguration.VanillaEncryptionConfiguration:
      Did not match:
         - @ConditionalOnMissingClass found unwanted class 'org.springframework.security.rsa.crypto.RsaSecretEncryptor' (OnClassCondition)

   EurekaDiscoveryClientConfigServiceBootstrapConfiguration:
      Did not match:
         - @ConditionalOnProperty (spring.cloud.config.discovery.enabled) did not find property 'spring.cloud.config.discovery.enabled' (OnPropertyCondition)
      Matched:
         - @ConditionalOnClass found required class 'org.springframework.cloud.config.client.ConfigServicePropertySourceLocator' (OnClassCondition)


Exclusions:
-----------

    None


Unconditional classes:
----------------------

    None



2019-06-18 14:52:03.534 DEBUG 32228 --- [           main] .c.l.ClasspathLoggingApplicationListener : Application started with classpath: unknown

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.1.5.RELEASE)

2019-06-18 14:52:03.566  INFO 32228 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:8888
2019-06-18 14:52:03.588 DEBUG 32228 --- [           main] o.s.web.client.RestTemplate              : HTTP GET http://localhost:8888/application/default
2019-06-18 14:52:03.651 DEBUG 32228 --- [           main] o.s.web.client.RestTemplate              : Accept=[application/xml, text/xml, application/json, application/*+xml, application/*+json]
2019-06-18 14:52:03.655  INFO 32228 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Connect Timeout Exception on Url - http://localhost:8888. Will be trying the next url if available

並且它自然會引發連接異常,因為它無法識別bootstrap.yml文件中的URL。

任何幫助將不勝感激,謝謝。

失敗的主要原因是我使用自己的父pom,用spring-boot-starter-parent更改后它開始工作。

當然,我將所需的部分(例如distributionManagement復制到eureka服務的pom中。

主要原因是spring boot parent pom在pom中使用resources指令,如下所示;

<resources>
  <resource>
    <filtering>true</filtering>
    <directory>${basedir}/src/main/resources</directory>
  </resource>
</resources>

手動添加到項目就行了!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM