Не связывает ==> Консул KV + Kotlin Spring Boot @ConfigurationProperties @ConstructorBinding - PullRequest
0 голосов
/ 03 ноября 2019

Мне нужно перенести наши конфигурации application.yml в Консул Хашикорпа. Я создал простое приложение Spring Boot для работы с необходимыми изменениями. Он загружает данные конфигурации из application.yml в строго типизированный класс.

Тем не менее, после закомментирования файла application.yml и включения консул в файле bootstrap.yml, когда я пытаюсь получить доступ к той же конфигурации вКонсул KV, который работает как образ Docker в моей системе, данные конфигурации всегда нулевые. Я, должно быть, упускаю что-то простое, но я в полной растерянности относительно того, что это такое. Ниже приведена соответствующая информация.

////////////////////////////////////////
// MyConsulApplication.kt
////////////////////////////////////////
@SpringBootApplication(scanBasePackages = ["com.example.myconsul"])
class MyConsulApplication

fun main(args: Array<String>) {
    runApplication<MyConsulApplication>(*args)
}
////////////////////////////////////////
// application.yml
////////////////////////////////////////
#myconsul:
#  message: howdy
////////////////////////////////////////
// bootstrap.yml
////////////////////////////////////////
server:
  port: 8080

spring:
  application:
    name: myconsul
  profiles:
    active: default
  cloud:
    consul:
      host: localhost
      port: 8500
      config:
        enabled: true  # Set to false to use the local application.yml file rather than the Consul configuration server.
        prefix: config
        defaultContext: application
      discovery:
        enabled: true
        instanceId: ${spring.application.name}:${random.value}
        healthCheckPath: /
        healthCheckInterval: 30s
////////////////////////////////////////
// AppProperties.kt
////////////////////////////////////////
@ConstructorBinding
//@RefreshScope
//@Scope("singleton")  // This is the default, but I wanted to be explicit about it.
@EnableConfigurationProperties(AppProperties::class)
@ConfigurationProperties("myconsul")
data class AppProperties(val message: String?) {

    @PostConstruct
    fun postConstruct() {
        println("====> $message")
    }
}
////////////////////////////////////////
// Consul KT Export
////////////////////////////////////////
[
    {
        "key": "config/myconsul/message",
        "flags": 0,
        "value": "SGFwcHkgSGFsbG93ZWVuIQ=="
    }
]
////////////////////////////////////////
// build.gradle.kts Dependencies
////////////////////////////////////////
extra["springCloudVersion"] = "Hoxton.BUILD-SNAPSHOT"

dependencies {
    // kapt dependencies required for IntelliJ auto complete of kotlin config properties class
    kapt("org.springframework.boot:spring-boot-configuration-processor")
    annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")
    implementation("org.springframework.cloud:spring-cloud-starter-consul-config")
    implementation("org.springframework.cloud:spring-cloud-starter-consul-discovery")

    implementation("org.springframework.boot:spring-boot-starter-actuator")
    implementation("org.springframework.boot:spring-boot-starter-webflux")
    implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
    implementation("org.jetbrains.kotlin:kotlin-reflect")
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor")
}
////////////////////////////////////////
// Console Logging of Launch
////////////////////////////////////////

2019-11-02 22:49:04.510  INFO 5401 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.retry.annotation.RetryConfiguration' of type [org.springframework.retry.annotation.RetryConfiguration$$EnhancerBySpringCGLIB$$1d6cbd94] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-11-02 22:49:04.519  INFO 5401 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$43c3286c] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)

 :: Spring Boot ::  (v2.2.1.BUILD-SNAPSHOT)

2019-11-02 22:49:05.521  INFO 5401 --- [           main] b.c.PropertySourceBootstrapConfiguration : Located property source: CompositePropertySource {name='consul', propertySources=[ConsulPropertySource {name='config/myconsul,default/'}, ConsulPropertySource {name='config/myconsul/'}, ConsulPropertySource {name='config/application,default/'}, ConsulPropertySource {name='config/application/'}]}
2019-11-02 22:49:05.526  INFO 5401 --- [           main] c.e.myconsul.MyConsulApplicationKt       : The following profiles are active: default
2019-11-02 22:49:06.453  WARN 5401 --- [           main] o.s.boot.actuate.endpoint.EndpointId     : Endpoint ID 'bus-env' contains invalid characters, please migrate to a valid format.
2019-11-02 22:49:06.658  WARN 5401 --- [           main] o.s.boot.actuate.endpoint.EndpointId     : Endpoint ID 'bus-refresh' contains invalid characters, please migrate to a valid format.
2019-11-02 22:49:06.745  WARN 5401 --- [           main] o.s.boot.actuate.endpoint.EndpointId     : Endpoint ID 'service-registry' contains invalid characters, please migrate to a valid format.
2019-11-02 22:49:06.901  INFO 5401 --- [           main] o.s.cloud.context.scope.GenericScope     : BeanFactory id=6becbf98-b3f5-3e17-8c2f-cd8e1a8f2d5d
2019-11-02 22:49:06.956  INFO 5401 --- [           main] faultConfiguringBeanFactoryPostProcessor : No bean named 'errorChannel' has been explicitly defined. Therefore, a default PublishSubscribeChannel will be created.
2019-11-02 22:49:06.961  INFO 5401 --- [           main] faultConfiguringBeanFactoryPostProcessor : No bean named 'taskScheduler' has been explicitly defined. Therefore, a default ThreadPoolTaskScheduler will be created.
2019-11-02 22:49:06.965  INFO 5401 --- [           main] faultConfiguringBeanFactoryPostProcessor : No bean named 'integrationHeaderChannelRegistry' has been explicitly defined. Therefore, a default DefaultHeaderChannelRegistry will be created.
2019-11-02 22:49:07.006  INFO 5401 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.retry.annotation.RetryConfiguration' of type [org.springframework.retry.annotation.RetryConfiguration$$EnhancerBySpringCGLIB$$1d6cbd94] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-11-02 22:49:07.041  INFO 5401 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'integrationChannelResolver' of type [org.springframework.integration.support.channel.BeanFactoryChannelResolver] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-11-02 22:49:07.046  INFO 5401 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'integrationDisposableAutoCreatedBeans' of type [org.springframework.integration.config.annotation.Disposables] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-11-02 22:49:07.058  INFO 5401 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.integration.config.IntegrationManagementConfiguration' of type [org.springframework.integration.config.IntegrationManagementConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-11-02 22:49:07.063  INFO 5401 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.boot.autoconfigure.integration.IntegrationAutoConfiguration$IntegrationJmxConfiguration' of type [org.springframework.boot.autoconfigure.integration.IntegrationAutoConfiguration$IntegrationJmxConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-11-02 22:49:07.070  INFO 5401 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration' of type [org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-11-02 22:49:07.074  INFO 5401 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'mbeanServer' of type [com.sun.jmx.mbeanserver.JmxMBeanServer] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-11-02 22:49:07.090  INFO 5401 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$43c3286c] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-11-02 22:49:07.594  WARN 5401 --- [           main] c.n.c.sources.URLConfigurationSource     : No URLs will be polled as dynamic configuration sources.
2019-11-02 22:49:07.594  INFO 5401 --- [           main] c.n.c.sources.URLConfigurationSource     : To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.
2019-11-02 22:49:07.601  INFO 5401 --- [           main] c.netflix.config.DynamicPropertyFactory  : DynamicPropertyFactory is initialized with configuration sources: com.netflix.config.ConcurrentCompositeConfiguration@83b0d0f
2019-11-02 22:49:07.752  INFO 5401 --- [           main] o.s.s.c.ThreadPoolTaskScheduler          : Initializing ExecutorService 'taskScheduler'
2019-11-02 22:49:07.946  INFO 5401 --- [           main] o.s.b.a.e.web.EndpointLinksResolver      : Exposing 2 endpoint(s) beneath base path '/actuator'
====> null
2019-11-02 22:49:08.105  WARN 5401 --- [           main] c.n.c.sources.URLConfigurationSource     : No URLs will be polled as dynamic configuration sources.
2019-11-02 22:49:08.105  INFO 5401 --- [           main] c.n.c.sources.URLConfigurationSource     : To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.
2019-11-02 22:49:08.287  INFO 5401 --- [           main] c.f.c.c.BeanFactoryAwareFunctionRegistry : Looking up function 'null' with acceptedOutputTypes: []
2019-11-02 22:49:08.474  WARN 5401 --- [           main] ockingLoadBalancerClientRibbonWarnLogger : You already have RibbonLoadBalancerClient on your classpath. It will be used by default. As Spring Cloud Ribbon is in maintenance mode. We recommend switching to BlockingLoadBalancerClient instead. In order to use it, set the value of `spring.cloud.loadbalancer.ribbon.enabled` to `false` or remove spring-cloud-starter-netflix-ribbon from your project.
2019-11-02 22:49:08.507  WARN 5401 --- [           main] eactorLoadBalancerClientRibbonWarnLogger : You have RibbonLoadBalancerClient on your classpath. LoadBalancerExchangeFilterFunction that uses it under the hood will be used by default. Spring Cloud Ribbon is now in maintenance mode, so we suggest switching to ReactorLoadBalancerExchangeFilterFunction instead. In order to use it, set the value of `spring.cloud.loadbalancer.ribbon.enabled` to `false` or remove spring-cloud-starter-netflix-ribbon from your project.
2019-11-02 22:49:08.555  INFO 5401 --- [           main] o.s.s.c.ThreadPoolTaskScheduler          : Initializing ExecutorService 'configWatchTaskScheduler'
2019-11-02 22:49:08.565  INFO 5401 --- [           main] o.s.s.c.ThreadPoolTaskScheduler          : Initializing ExecutorService 'catalogWatchTaskScheduler'
2019-11-02 22:49:08.668  INFO 5401 --- [           main] o.s.c.s.m.DirectWithAttributesChannel    : Channel 'myconsul-1.springCloudBusInput' has 1 subscriber(s).
2019-11-02 22:49:08.777  INFO 5401 --- [           main] o.s.i.monitor.IntegrationMBeanExporter   : Registering MessageChannel springCloudBusInput
2019-11-02 22:49:08.860  INFO 5401 --- [           main] o.s.i.monitor.IntegrationMBeanExporter   : Registering MessageChannel errorChannel
2019-11-02 22:49:08.896  INFO 5401 --- [           main] o.s.i.monitor.IntegrationMBeanExporter   : Registering MessageChannel nullChannel
2019-11-02 22:49:08.910  INFO 5401 --- [           main] o.s.i.monitor.IntegrationMBeanExporter   : Registering MessageChannel springCloudBusOutput
2019-11-02 22:49:08.925  INFO 5401 --- [           main] o.s.i.monitor.IntegrationMBeanExporter   : Registering MessageHandler org.springframework.cloud.stream.binding.StreamListenerMessageHandler@7497a554
2019-11-02 22:49:08.973  INFO 5401 --- [           main] o.s.i.monitor.IntegrationMBeanExporter   : Registering MessageHandler errorLogger
2019-11-02 22:49:09.058  INFO 5401 --- [           main] o.s.i.endpoint.EventDrivenConsumer       : Adding {logging-channel-adapter:_org.springframework.integration.errorLogger} as a subscriber to the 'errorChannel' channel
2019-11-02 22:49:09.058  INFO 5401 --- [           main] o.s.i.channel.PublishSubscribeChannel    : Channel 'myconsul-1.errorChannel' has 1 subscriber(s).
2019-11-02 22:49:09.058  INFO 5401 --- [           main] o.s.i.endpoint.EventDrivenConsumer       : started bean '_org.springframework.integration.errorLogger'
2019-11-02 22:49:09.121  INFO 5401 --- [           main] b.c.PropertySourceBootstrapConfiguration : Located property source: CompositePropertySource {name='consul', propertySources=[ConsulPropertySource {name='config/myconsul,default/'}, ConsulPropertySource {name='config/myconsul/'}, ConsulPropertySource {name='config/application,default/'}, ConsulPropertySource {name='config/application/'}]}
2019-11-02 22:49:09.157  INFO 5401 --- [           main] o.s.i.endpoint.EventDrivenConsumer       : Adding {message-handler:outbound.springCloudBus} as a subscriber to the 'springCloudBusOutput' channel
2019-11-02 22:49:09.157  INFO 5401 --- [           main] o.s.c.s.m.DirectWithAttributesChannel    : Channel 'myconsul-1.springCloudBusOutput' has 1 subscriber(s).
2019-11-02 22:49:09.157  INFO 5401 --- [           main] o.s.i.endpoint.EventDrivenConsumer       : started bean 'outbound.springCloudBus'
2019-11-02 22:49:09.170  INFO 5401 --- [           main] o.s.c.c.b.ConsulInboundMessageProducer   : started org.springframework.cloud.consul.binder.ConsulInboundMessageProducer@878feb2
2019-11-02 22:49:09.339  INFO 5401 --- [           main] o.s.b.web.embedded.netty.NettyWebServer  : Netty started on port(s): 8080
2019-11-02 22:49:09.375  INFO 5401 --- [           main] o.s.c.c.s.ConsulServiceRegistry          : Registering service with consul: NewService{id='myconsul-9d80f0a272c1126ed0ec586ee888be1f', name='myconsul', tags=[secure=false], address='192.168.0.11', meta=null, port=8080, enableTagOverride=null, check=Check{script='null', interval='30s', ttl='null', http='http://192.168.0.11:8080/', method='null', header={}, tcp='null', timeout='null', deregisterCriticalServiceAfter='null', tlsSkipVerify=null, status='null'}, checks=null}
2019-11-02 22:49:09.404  INFO 5401 --- [           main] c.e.myconsul.MyConsulApplicationKt       : Started MyConsulApplicationKt in 6.34 seconds (JVM running for 7.778)

1 Ответ

0 голосов
/ 04 ноября 2019

Итак, я решил эту проблему, создав java-проект и заставив его работать. Затем на основе моего Java-проекта я создал реактивную версию Kotlin. Оба эти проекта работают должным образом и являются автономными. Я надеюсь, что они могут помочь другим. Вот ссылки на проекты:

Пример значения ключа консула Java

Пример значения ключа консула Kotlin

...