custom gateway and Spring injection failure

270 views
Skip to first unread message

jorgheymans

unread,
Sep 5, 2016, 7:01:02 AM9/5/16
to Axon Framework Users
Hi,

I added a custom gateway to my application:

  <bean class="org.axonframework.commandhandling.gateway.CommandGatewayFactoryBean">
    <property name="commandBus" ref="commandBus"/>
    <property name="gatewayInterface" value="my.CustomGateway"/>
  </bean>

and where necessary i changed the usage of the default command gateway to this one

  @Autowired
  private CustomGateway gateway;

The application fails to start however, saying that it found two beans of this type:

2016-09-05 12:20:52.934  WARN 6928 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'instanceService': Unsatisfied dependency expressed through field 'gateway': No qualifying bean of type [my.CustomGateway] is defined: expected single matching bean but found 2: org.axonframework.commandhandling.gateway.CommandGatewayFactoryBean#0,customGateway; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [eu.europa.ec.ccf.eckl.service.common.CustomGateway] is defined: expected single matching bean but found 2: org.axonframework.commandhandling.gateway.CommandGatewayFactoryBean#0,customGateway

When i add an id "gateway" to the spring declaration the error goes away, presumably because Spring matches the field name to the bean name. Is this expected behavior and if yes where is the second 'customGateway' bean coming from ?


Jorg

Allard Buijze

unread,
Sep 5, 2016, 4:23:42 PM9/5/16
to Axon Framework Users
It might be that, for whatever reason, the bean is instantiated twice. Giving it an ID will cause the second bean(definition) to overwrite the first.

However, I have no clue why it would be included twice. Spring usually doesn't parses beans more than once, unless you deliberately mention two different bean configurations.
--
You received this message because you are subscribed to the Google Groups "Axon Framework Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to axonframewor...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

jorgheymans

unread,
Sep 6, 2016, 4:23:07 AM9/6/16
to Axon Framework Users
Thanks, a bit of debugging revealed that in fact it was mybatis adding the gateway interface as a mapper, so i narrowed its scanning configuration a bit and it works as intended now :-)

Jorg
Reply all
Reply to author
Forward
0 new messages