3.17 Micronaut Beans And Spring
The MicronautBeanProcessor class is a BeanFactoryPostProcessor
which will add Micronaut beans to a Spring Application Context. An instance of MicronautBeanProcessor
should be added to the Spring Application Context. MicronautBeanProcessor
requires a constructor parameter which represents a list of the types of Micronaut beans which should be added to the Spring Application Context. The processor may be used in any Spring application. As an example, a Grails 3 application could take advantage of MicronautBeanProcessor
to add all of the Micronaut HTTP Client beans to the Spring Application Context with something like the folowing:
// grails-app/conf/spring/resources.groovy
import io.micronaut.spring.beans.MicronautBeanProcessor
import io.micronaut.http.client.annotation.Client
beans = {
httpClientBeanProcessor MicronautBeanProcessor, Client
}
Multiple types may be specified:
// grails-app/conf/spring/resources.groovy
import io.micronaut.spring.beans.MicronautBeanProcessor
import io.micronaut.http.client.annotation.Client
import com.sample.Widget
beans = {
httpClientBeanProcessor MicronautBeanProcessor, [Client, Widget]
}
In a non-Grails application something similar may be specified using any of Spring’s bean definition styles:
Unresolved directive in <stdin> - include::spring/src/test/groovy/io/micronaut/spring/beans/MicronautBeanProcessorByAnnotationTypeSpec.groovy[tags=springconfig, indent=0]