spring-cloud / spring-cloud-config

External configuration (server and client) for Spring Cloud
Apache License 2.0
1.96k stars 1.29k forks source link

Cloud Config Client Located Server: properties not loaded. #2203

Closed cobar79 closed 1 year ago

cobar79 commented 1 year ago

I am sure this is some kind of boot/cloud version dependency issue but I can't figure out the combination of dependencies and property values.

Config Servers starts and properties are available in browser localhost:8888/master/ucdp-ingest localhost:8888/master/ucdp-ingest-dev

$ java --version
openjdk 11.0.14.1 2022-02-08 LTS
OpenJDK Runtime Environment Corretto-11.0.14.10.1 (build 11.0.14.1+10-LTS)
OpenJDK 64-Bit Server VM Corretto-11.0.14.10.1 (build 11.0.14.1+10-LTS, mixed mode)

Therefore according to 2021-0-3 Availability and the java version we use, I went with Spring Boot: 2.7.6 Spring Cloud: 2021.0.3

Client:

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.6</version>
        <relativePath/>
    </parent>
    <properties>
        <aws-sdk.version>1.12.368</aws-sdk.version>
        <commons-lang3.version>3.12.0</commons-lang3.version>
        <jacoco.version>0.8.8</jacoco.version>
        <jasypt-spring-boot.version>3.0.5</jasypt-spring-boot.version>
        <java.version>11</java.version>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <spring-cloud.version>2021.0.3</spring-cloud.version>
        <spring-cloud-stream-kinesis-binder.version>2.2.0</spring-cloud-stream-kinesis-binder.version>
        <springdoc-openapi-ui.version>1.6.14</springdoc-openapi-ui.version>
        <swagger-maven-plugin.version>2.1.6</swagger-maven-plugin.version>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>
        <!-- Spring cloud -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>

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

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

Note no "spring-cloud-starter-bootstrap" per documentation. Interestingly "spring.profiles.active" shows deprecated. However, according to Spring 2.4 docs it should be spring.config.activate.on-profile. This doesn't resolve as system property>

  -Dspring.config.activate.on-profile=dev
2022-12-23 15:28:51.358  INFO 36316 --- [           main] c.b.u.ucdp.ingest.UcdpIngestApplication  : No active profile set, falling back to 1 default profile: "default"

Client: application.yml

spring:
  application:
    name: ucdp-ingest
  cloud:
    config:
      name: ${spring.application.name}
      uri: http://localhost:8888
      username: ----------
      password: ---------
      request-connect-timeout: 3000
      request-read-timeout: 3000
      retry:
        initial-interval: 1000
        max-attempts: 6
      label: master
      fail-fast: true
  config:
    import: "configserver:"

server:
  port: 8300
  servlet:
    context-path: /${spring.application.name}

  # Actuator
  management:
    #opt-in use enabled-by-default: false then enable what you want. default = true
    enabled-by-default: true
    server:
      port: ${server.port}
    endpoints:
      web:
        base-path: ${server.servlet.context-path}
        exposure:
          include: "*"
    endpoint:
      env:
        enabled: true
      health:
        show-details: always
        enabled: true
      info:
        enabled: true
#      shutdown:
#        enabled: true

#OpenAPI
springdoc:
  api-docs:
    path: /docs/api-docs
    version: openapi_3_1
  swagger-ui:
    path: /docs/swagger-ui
  paths-to-match: /**

REMOTE application-ucdp-ingest.yml

app:
  ucdp:
    url: https://ucdpapi.pcr.uu.se/api
    connect-timeout-millis: 2000
    read-timeout-seconds: 2000
  ged:
    job:
      enabled: true
      cron: "20 49 11 * * ?"
    #Max page size is 1000
    pageSize: 1000
    uri: /gedevents/21.1

REMOTE application-ucdp-ingest-dev.yml contains mongo and aws connection properties. Mongo also failed to connect because properties were not loaded remotely.

LOGS:

+ /c/sfw/java/jdk11.0.14_10/bin/java -Dspring.config.activate.on-profile=dev -Dlogging.config=/c/projects/ucdp-ingest/ucdp-ingest-app/config/logback.xml -jar /c/projects/ucdp-ingest/ucdp-ingest-app/target/ucdp-ingest-app-0.0.1-SNAPSHOT.jar

2022-12-23 15:30:50.081  INFO 20496 --- [           main] c.b.u.ucdp.ingest.UcdpIngestApplication  : Starting UcdpIngestApplication v0.0.1-SNAPSHOT using Java 11.0.14.1 on BRANDA-BSTAQ-PC with PID 20496 (C:\projects\ucdp-ingest\ucdp-ingest-app\target\ucdp-ingest-app-0.0.1-SNAPSHOT.jar started by BruceRandall in C:\projects\ucdp-ingest\ucdp-ingest-app)
2022-12-23 15:30:50.086  INFO 20496 --- [           main] c.b.u.ucdp.ingest.UcdpIngestApplication  : The following 1 profile is active: "dev"
2022-12-23 15:30:50.136  INFO 20496 --- [           main] o.s.c.c.c.ConfigServerConfigDataLoader   : Fetching config from server at : http://localhost:8888
2022-12-23 15:30:50.137  INFO 20496 --- [           main] o.s.c.c.c.ConfigServerConfigDataLoader   : Located environment: name=ucdp-ingest, profiles=[dev], label=master, version=7102644c36175df62e3a3952793021cdf730583a, state=null
2022-12-23 15:30:51.495  INFO 20496 --- [           main] ptablePropertiesBeanFactoryPostProcessor : Post-processing PropertySource instances
2022-12-23 15:30:51.496  INFO 20496 --- [           main] c.u.j.EncryptablePropertySourceConverter : Skipping PropertySource configurationProperties [class org.springframework.boot.context.properties.source.ConfigurationPropertySourcesPropertySource
2022-12-23 15:30:51.498  INFO 20496 --- [           main] c.u.j.EncryptablePropertySourceConverter : Skipping PropertySource servletConfigInitParams [class org.springframework.core.env.PropertySource$StubPropertySource
2022-12-23 15:30:51.498  INFO 20496 --- [           main] c.u.j.EncryptablePropertySourceConverter : Skipping PropertySource servletContextInitParams [class org.springframework.core.env.PropertySource$StubPropertySource
2022-12-23 15:30:51.499  INFO 20496 --- [           main] c.u.j.EncryptablePropertySourceConverter : Converting PropertySource systemProperties [org.springframework.core.env.PropertiesPropertySource] to EncryptableMapPropertySourceWrapper
2022-12-23 15:30:51.499  INFO 20496 --- [           main] c.u.j.EncryptablePropertySourceConverter : Converting PropertySource systemEnvironment [org.springframework.boot.env.SystemEnvironmentPropertySourceEnvironmentPostProcessor$OriginAwareSystemEnvironmentPropertySource] to EncryptableSystemEnvironmentPropertySourceWrapper
2022-12-23 15:30:51.500  INFO 20496 --- [           main] c.u.j.EncryptablePropertySourceConverter : Converting PropertySource random [org.springframework.boot.env.RandomValuePropertySource] to EncryptablePropertySourceWrapper
2022-12-23 15:30:51.500  INFO 20496 --- [           main] c.u.j.EncryptablePropertySourceConverter : Converting PropertySource cachedrandom [org.springframework.cloud.util.random.CachedRandomPropertySource] to EncryptablePropertySourceWrapper
2022-12-23 15:30:51.500  INFO 20496 --- [           main] c.u.j.EncryptablePropertySourceConverter : Converting PropertySource springCloudClientHostInfo [org.springframework.core.env.MapPropertySource] to EncryptableMapPropertySourceWrapper
2022-12-23 15:30:51.500  INFO 20496 --- [           main] c.u.j.EncryptablePropertySourceConverter : Converting PropertySource configClient [org.springframework.core.env.MapPropertySource] to EncryptableMapPropertySourceWrapper
2022-12-23 15:30:51.500  INFO 20496 --- [           main] c.u.j.EncryptablePropertySourceConverter : Converting PropertySource Config resource 'file [config\application.yml]' via location 'optional:file:./config/' [org.springframework.boot.env.OriginTrackedMapPropertySource] to EncryptableMapPropertySourceWrapper

2022-12-23 15:30:51.664  INFO 20496 --- [           main] c.u.j.filter.DefaultLazyPropertyFilter   : Property Filter custom Bean not found with name 'encryptablePropertyFilter'. Initializing Default Property Filter
2022-12-23 15:30:51.673  INFO 20496 --- [           main] c.u.j.r.DefaultLazyPropertyResolver      : Property Resolver custom Bean not found with name 'encryptablePropertyResolver'. Initializing Default Property Resolver
2022-12-23 15:30:51.675  INFO 20496 --- [           main] c.u.j.d.DefaultLazyPropertyDetector      : Property Detector custom Bean not found with name 'encryptablePropertyDetector'. Initializing Default Property Detector
2022-12-23 15:30:52.246  INFO 20496 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8300 (http)
2022-12-23 15:30:52.256  INFO 20496 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2022-12-23 15:30:52.256  INFO 20496 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.69]
2022-12-23 15:30:52.351  INFO 20496 --- [           main] o.a.c.c.C.[.[localhost].[/ucdp-ingest]   : Initializing Spring embedded WebApplicationContext
2022-12-23 15:30:52.351  INFO 20496 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2212 ms

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'gedJob' defined in URL [jar:file:/C:/projects/ucdp-ingest/ucdp-ingest-app/target/ucdp-ingest-app-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/com/bar/udl/ucdp/ingest/service/impl/GedJob.class]: Initialization of bean failed; nested exception is java.lang.IllegalStateException: Encountered invalid @Scheduled method 'executeJob': Could not resolve placeholder 'app.ged.job.cron' in value "${app.ged.job.cron}"
ryanjbaxter commented 1 year ago

One thing I notice is that you have bother spring-boot-starter-web and spring-boot-starter-webflux on the classpath. You should choose one and not have both.

Can you provide a complete, minimal, verifiable sample that reproduces the problem? It should be available as a GitHub (or similar) project or attached to this issue as a zip file.

spring-cloud-issues commented 1 year ago

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

spring-cloud-issues commented 1 year ago

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.