无法从bootstrap.yml读取配置服务器uri

时间:2019-06-18 07:25:37

标签: java spring spring-boot spring-cloud

我正在尝试使用以下 pom 创建一个eureka服务器注册表以连接到配置服务器,但是它无法连接配置服务器,因为它无法从读取正确的配置服务器uri bootstrap.yml文件;

 <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 。但它吐出以下输出;

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。

任何帮助将不胜感激,谢谢。

1 个答案:

答案 0 :(得分:0)

失败的主要原因是我使用自己的父pom,并用spring-boot-starter-parent对其进行了更改后,它开始起作用。

我当然将诸如distributionManagement之类的必需部分复制到了eureka服务的pom中。

主要原因是Spring Boot父pom在pom中使用resources指令,如下所示;

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

手动将此添加到项目中就可以了!