micronaut-projects / micronaut-core

Micronaut Application Framework
http://micronaut.io
Apache License 2.0
6.1k stars 1.07k forks source link

Support ordering of eagerly initialized singletons #3715

Open onyn opened 4 years ago

onyn commented 4 years ago

I'm using micronaut 2.0.0 and configure logback levels via application.yml for apache kafka and hikaricp:

logger:
  levels:
    io.micronaut.logging.PropertiesLoggingLevelsConfigurer: DEBUG
    org.apache.kafka.clients.consumer.ConsumerConfig: WARN
    org.apache.kafka.clients.producer.ProducerConfig: WARN
    org.apache.kafka.clients.admin.AdminClientConfig: WARN
    com.zaxxer.hikari.HikariDataSource: WARN

Unfortunately, kafka and hikaricp beans initializes too early. Just before micronaut configures log levels. And I see in my logs bunch of records with INFO level which I does not expected to see:

18:22:31.613 [main] INFO  com.zaxxer.hikari.HikariDataSource - pool1 - Starting...
18:22:31.719 [main] INFO  com.zaxxer.hikari.HikariDataSource - pool1 - Start completed.
18:22:31.766 [main] INFO  org.apache.kafka.clients.consumer.ConsumerConfig - ConsumerConfig values: 
...snipped...
18:22:31.937 [main] DEBUG i.m.logging.PropertiesLoggingLevelsConfigurer - Setting log level 'WARN' for logger: 'org.apache.kafka.clients.consumer.ConsumerConfig'
18:22:31.937 [main] DEBUG i.m.logging.PropertiesLoggingLevelsConfigurer - Setting log level 'WARN' for logger: 'org.apache.kafka.clients.producer.ProducerConfig'
18:22:31.937 [main] DEBUG i.m.logging.PropertiesLoggingLevelsConfigurer - Setting log level 'WARN' for logger: 'org.apache.kafka.clients.admin.AdminClientConfig'

Is it possible to force PropertiesLoggingLevelsConfigurer bean to load very first?

Environment Information

jameskleeh commented 4 years ago

@graemerocher Thoughts on supporting @Context(order = ? Then the context beans would be initialized in that order

graemerocher commented 4 years ago

Better to support @Order which there is already a PR for

jameskleeh commented 4 years ago

It's a different concept though. Beans would be ordered compared to all other context beans, where as @Order is about comparing the beans to other beans of that type. I can envision a requirement for the value to be different.