Description
Feature description
When a micronaut library is created using io.micronaut.library
plugin, all of the bean definitions are added to META-INF/services/io.micronaut.inject.BeanDefinitionReference
. As the result, when such library is added to a micronaut application all of its beans are imported. While it might be a reasonable default behavior, there is frequently a need for an application to import only selected beans from a library similar to Spring Boot EnableScheduling which imports specific SchedulingConfiguration.class (i.e. different applications could choose to import different components). It's my understanding that there is currently no way to control either:
- which beans are included in
META-INF/services/io.micronaut.inject.BeanDefinitionReference
as part of a library jar - or which of the beans from a library jar get imported
I've removed META-INF/services/io.micronaut.inject.BeanDefinitionReference
from the library jar explicitly in my build.gradle:
jar {
exclude('META-INF/services/io.micronaut.inject.BeanDefinitionReference')
}
and then used @Import
in the application to explicitly import the desired components.
I wonder if there is a better way to do this. Thanks in advance for the consideration!