I have a spring boot app that worked fine up until I updated from 1.2.0.M1 to 1.2.0.M2. The app will not build because of an UnsatisfiedDependencyException resulting from spring-boot RabbitAutoConfiguration:
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'jmsMessagingTemplate' defined in class path resource [org/springframework/boot/autoconfigure/amqp/RabbitAutoConfiguration$MessagingTemplateConfiguration.class]:
Unsatisfied dependency expressed through constructor argument with index 0 of type [org.springframework.amqp.rabbit.core.RabbitTemplate]: :
No qualifying bean of type [org.springframework.amqp.rabbit.core.RabbitTemplate] is defined:
expected single matching bean but found 3: looperTemplate,pingTemplate,orgRequestTemplate; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException:
No qualifying bean of type [org.springframework.amqp.rabbit.core.RabbitTemplate] is defined:
expected single matching bean but found 3: looperTemplate,pingTemplate,orgRequestTemplate
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:751) ~[spring-beans-4.1.1.RELEASE.jar:4.1.1.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:466) ~[spring-beans-4.1.1.RELEASE.jar:4.1.1.RELEASE]
The problem is I do have RabbitMQ templates, but I have 3 of them and it needs a qualifier to select a single template. However this code is in spring-boot, not my code. I would prefer not to have to alter spring-boot code, but I am not sure what I should do in my code to prevent this exception.
I can see the offending jmsMessagingTemplate was added in the 1.2.0.M2 version. The naming of this is also misleading as I do not have JMS enabled in my app (although this is a RabbitMQ specific auto configuration file in spring-boot).
Any suggestions on how I can configure my code without eliminating templates or modifying spring-boot code?
I've created #1701 to track the naming issue. You should read rabbitMessagingTemplate there.
There are several auto configuration instances in Boot that requires certain types to be flagged with #Primary if they're not using the "default" name. For instance a JdbcTemplate is created for you automatically if none exists and a datasource is present. If you have more than one you should either name one dataSource or flag one of them as #Primary.
In your case, the messaging auto config for RabbitMQ expects one RabbitTemplate to be named rabbitTemplate or flag one of the three as #Primary.
This is annoying and we should do better. I've created #1702 for that.
Let me know if that works out for you. Thanks!
Related
I am new to springboot.
Doing a migration of my service (kotlin)following a guide written at work.
Got this weird exception and cannot find any documentation.
Parameter 3 of method multipleOpenApiResource in org.springdoc.webflux.core.MultipleOpenApiSupportConfiguration required a bean of type 'org.springdoc.core.GenericResponseService' that could not be found.
Action:
Consider defining a bean of type 'org.springdoc.core.GenericResponseService' in your configuration.
Should I define this bean at my #Configuration?
Is this a symptom of dependency missing or bad dependency wiring?
One of my beans was called ResponseBuilder and it conflicted with spring boot.
Sorry for the trouble
I am having two beans in different packages out of which one of them is a library so cannot edit, and execution gives the
org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type '' available:
For current purpose I want the bean in the library to be the primary bean, is there a way to avoid using the second bean which i can edit , without deleting the bean?
So far have only seen the #Primary annotation
when spring is trying to inject the dependency it found to to beans for it .
so you have add #Qualifier annotation and give the corresponding class in it which you want to inject
I'm using Spring Boot and trying use Spring integration (because I want to use its SFTP client). But I got the following error:
Description:
Parameter 0 of constructor in com.example.demo.service.ServiceOne required a single bean, but 2 were found:
- applicationTaskExecutor: defined by method 'applicationTaskExecutor' in class path resource [org/springframework/boot/autoconfigure/task/TaskExecutionAutoConfiguration.class]
- taskScheduler: defined in null
Action:
Consider marking one of the beans as #Primary, updating the consumer to accept multiple beans, or using #Qualifier to identify the bean that should be consumed
I'm sure that the error happens after adding dependencies for spring-integration. I've tried to use #Qualifier("applicationTaskExecutor") and creating a bean with #Primary annotation but still unable to run the application. How to fix it?
As error stated there are two TaskExecutor beans in the application context.
One is auto-configured by the TaskExecutionAutoConfiguration and another by Spring Integration for its pollers features which is essentially a TaskScheduler.
What the error description suggest is to use a #Qualifier("applicationTaskExecutor") on the ServiceOne 's Parameter 0 of constructor. You don't need to have #Primary bean because the story is about beans created outside of your code.
I am following this example here:- http://www.baeldung.com/spring-graphql
for me the GraphQLSchema bean is not getting autoregistered. it throws me this error:-
No qualifying bean of type 'graphql.schema.GraphQLSchema' available
my Pom file has all requried Spring boot dependecies:-
graphql-spring-boot-starter
graphql-java-tools
graphiql-spring-boot-starter
I have following settings in application.proerties:-
graphql.root=/v1
graphql.servlet.mapping=${graphql.root}/graphql
graphql.servlet.enabled=true
graphql.servlet.corsEnabled=true
Not sure what am I missing, Do I need to explicitly define this bean as on this page:- https://github.com/graphql-java/graphql-spring-boot/blob/master/example/src/main/java/com/embedler/moon/graphql/boot/sample/ApplicationBootConfiguration.java.
But I thought it will autocreate for me, I just need to have *.graphqls on my class path.
I have followed the same tutorial as well and encountered the same error. I ended up figuring out what the issue was and it is that you need to add #Component to the Query class that the tutorial describes.
Once that was done graphiql was finally finding the schema and the /graphql end-point was exposed.
I'v added one Akka actor to my app that works with Spring and OSGI.
I try to use Actor from Spring #Component bean like this:
private final ActorSystem system = ActorSystem.create("actor-system");
private ActorRef managerActorRef = system.actorOf(Props.create(ManagerActor.class), "ldapManagerActor");
When I start the app it throws an exception (No configuration setting found for key 'akka'):
Instantiation of bean failed; nested exception is org.springframework.
beans.BeanInstantiationException: Could not instantiate bean class [com.myconpany....ByBean]: Constructor threw exception; nested exception is com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'akka'
I've look at this: doc. And seems the root of my problem is related to class loader that I should pass to/for akka-system and application.conf file that describes this.
But I could not find appropriate stets to make it all working so far.
Could someone help?
My tries:
Flowing this article.
When I put:
<bean id="actorSystem" class="akka.actor.ActorSystem" factory-method="create" scope="singleton"></bean>
I have the similar error:
Could not autowire field: private akka.actor.ActorSystem
com.typesafe.config.ConfigException$Missing: No configuration setting fou
nd for key 'akka'
If you just want to use Akka actors you don't need to pass in application.conf settings. You can just use the default. Make sure you have the config library on your class path.
You didn't mention what version of Akka youre using, however if you grab the latest Akka 2.2 RC you can use an IndirectActorProducer to handle the spring wiring.
See this article on how to do that; http://blog.nemccarthy.me/?p=272
You should also tell Spring to call shutdown on the ActorSystem to cleanly shutdown. There is also an updated guide on how to integrate the ActorSystem into Spring or a web app here