spring-native
spring-native copied to clipboard
Add support for spring-cloud-starter-stream-rabbit
Hello, I'm trying to migrate a spring microsservice to spring native, but some things are going wrong. I'm using org.springframework.cloud:spring-cloud-starter-bus-amqp dependency with rabbitMQ, and when my application is starting, I get this error:
***************************
APPLICATION FAILED TO START
***************************
Description:
Native reflection configuration for org.springframework.cloud.stream.binder.rabbit.config.RabbitServiceAutoConfiguration is missing.
then I created the follow configuration:
@TypeHint(
typeNames = [
"org.springframework.cloud.stream.binder.rabbit.config.RabbitServiceAutoConfiguration",
"org.springframework.cloud.stream.binder.rabbit.config.RabbitHealthIndicatorConfiguration",
"org.springframework.cloud.stream.binder.rabbit.config.NoCloudProfile",
"org.springframework.cloud.stream.binder.rabbit.config.CloudProfile",
"org.springframework.cloud.stream.binder.rabbit.config.CloudProfile\$CloudConnectors",
"org.springframework.cloud.stream.binder.rabbit.config.CloudProfile\$CloudConnectors\$UseCloudConnectors",
"org.springframework.cloud.stream.binder.rabbit.config.CloudProfile\$CloudConnectors\$OverrideCloudConnectors",
"org.springframework.cloud.stream.binder.rabbit.config.CloudProfile\$NoCloudConnectors",
],
access = AccessBits.ALL
)
@Configuration
class RabbitServiceAutoConfigurationNativeConfiguration
but, the build failed with the message:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':generateAot'.
> ERROR: in 'org.springframework.cloud.stream.binder.rabbit.config.RabbitMessageChannelBinderConfiguration' these methods are directly invoking methods marked @Bean: [rabbitMessageChannelBinder, rabbitMessageChannelBinder, rabbitMessageChannelBinder] - due to the enforced proxyBeanMethods=false for components in a native-image, please consider refactoring to use instance injection. If you are confident this is not going to affect your application, you may turn this check off using -Dspring.native.verify=false.
then I placed the taks:
springAot{
verify.set(false)
}
but now Spring failed to instantiate RabbitServiceAutoConfiguration, which is an abstract class
main] o.s.boot.SpringApplication : Application run failed
org.springframework.context.ApplicationContextException: Failed to start bean 'inputBindingLifecycle'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'rabbitServiceAutoConfiguration': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.stream.binder.rabbit.config.RabbitServiceAutoConfiguration]: Is it an abstract class?; nested exception is java.lang.InstantiationException: Cannot instantiate class org.springframework.cloud.stream.binder.rabbit.config.RabbitServiceAutoConfiguration
Am I missing something? Is Spring Native compatible with spring-cloud-starter-bus-amqp? I'm stuck at this stage and I appreciate any help.
+--- org.springframework.cloud:spring-cloud-starter-bus-amqp -> 3.0.3 | +--- org.springframework.cloud:spring-cloud-starter-stream-rabbit:3.1.3 | | --- org.springframework.cloud:spring-cloud-stream-binder-rabbit:3.1.3 | | | --- org.springframework.cloud.stream.binder.rabbit.config.RabbitServiceAutoConfiguration.class
Spring Version: "2.5.2" io.spring.dependency-management: "1.0.11.RELEASE" experimental.aot: "0.10.2" buildtools.native: "0.9.1" kotlin-version: "1.5.21"
Any tips?
@israeljesus2zup Manage to find out an alternative? I am facing the same issue.
I am using Spring Native to build a spring-cloud-azure-stream-binder-eventhubs
sample, I got a similar issue, then I add more hits in the spring-cloud-azure-native-configuration
module, the more exception will be found.
https://github.com/moarychan/azure-sdk-for-java/blob/b2ac9151fcdff0e7a9a26cd8aa745b788b954534/sdk/spring/spring-cloud-azure-stream-binder-eventhubs/src/main/java/com/azure/spring/cloud/stream/binder/eventhubs/config/EventHubsBinderConfiguration.java#L71-L115,they are mutually exclusive beans.
The bean EventHubsChannelProvisioner
should be activated only once, actual the bean eventHubChannelProvisioner
will be created, but when executing native image, the below exception is found:
at com.azure.spring.sample.eventhubs.binder.EventHubBinderApplication.main(EventHubBinderApplication.java:22) ~[eventhubs-binder.exe:1.0.0]
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'eventHubBinder' defined in com.azure.spring.cloud.stream.binder.eventhubs.config.EventHubsBinderConfiguration: Unsatisfied d
ependency expressed through method 'eventHubBinder' parameter 0; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'com.azure.spring.cloud.stream.binder.eventhubs.core.
provisioning.EventHubsChannelProvisioner' available: expected single matching bean but found 2: eventHubChannelProvisioner,eventHubChannelArmProvisioner
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:800) ~[na:na]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:541) ~[na:na]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352) ~[na:na]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195) ~[na:na]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[na:na]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[na:na]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[na:na]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[na:na]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[na:na]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[na:na]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:953) ~[na:na]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[na:na]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[na:na]
at org.springframework.cloud.stream.binder.DefaultBinderFactory.initializeBinderContextSimple(DefaultBinderFactory.java:471) ~[na:na]
at org.springframework.cloud.stream.binder.DefaultBinderFactory.getBinderInstance(DefaultBinderFactory.java:265) ~[na:na]
at org.springframework.cloud.stream.binder.DefaultBinderFactory.doGetBinder(DefaultBinderFactory.java:223) ~[na:na]
at org.springframework.cloud.stream.binder.DefaultBinderFactory.getBinder(DefaultBinderFactory.java:151) ~[na:na]
at org.springframework.cloud.stream.binding.BindingService.getBinder(BindingService.java:389) ~[na:na]
at org.springframework.cloud.stream.binding.BindingService.bindProducer(BindingService.java:273) ~[na:na]
at org.springframework.cloud.stream.binding.BindingService.bindProducer(BindingService.java:297) ~[na:na]
at org.springframework.cloud.stream.binding.BindingService.bindProducer(BindingService.java:301) ~[na:na]
at org.springframework.cloud.stream.binding.AbstractBindableProxyFactory.createAndBindOutputs(AbstractBindableProxyFactory.java:142) ~[na:na]
at org.springframework.cloud.stream.binding.OutputBindingLifecycle.doStartWithBindable(OutputBindingLifecycle.java:58) ~[na:na]
at java.util.LinkedHashMap$LinkedValues.forEach(LinkedHashMap.java:608) ~[na:na]
at org.springframework.cloud.stream.binding.AbstractBindingLifecycle.start(AbstractBindingLifecycle.java:57) ~[eventhubs-binder.exe:1.0.0]
at org.springframework.cloud.stream.binding.OutputBindingLifecycle.start(OutputBindingLifecycle.java:34) ~[na:na]
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:178) ~[na:na]
... 14 common frames omitted
Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'com.azure.spring.cloud.stream.binder.eventhubs.core.provisioning.EventHubsChannelProvisioner' available: expected single match
ing bean but found 2: eventHubChannelProvisioner,eventHubChannelArmProvisioner
at org.springframework.beans.factory.config.DependencyDescriptor.resolveNotUnique(DependencyDescriptor.java:220) ~[na:na]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1367) ~[na:na]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1309) ~[na:na]
Spring Native is now superseded by Spring Boot 3 official native support, see the related reference documentation for more details.
As a consequence, I am closing this issue, and recommend trying your use case with latest Spring Boot 3 version. If you still experience the issue reported here, please open an issue directly on the related Spring project (Spring Framework, Data, Security, Boot, Cloud, etc.) with a reproducer.
Thanks for your contribution on the experimental Spring Native project, we hope you will enjoy the official native support introduced by Spring Boot 3.