custom gateway and Spring injection failure

Hi,

I added a custom gateway to my application:

`

`

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

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.

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 :slight_smile:

Jorg