Axon & Spring 4.0.0 compatibility issue

Hi,
I’ve noticed that after upgrading to spring 4.0.0 autowiring repositories is no longer possible.
It will throw an exception indicating that it is not possible to autowire Repository because there are no such bean.
If you leave out the generics it will work.
I use the axon 2.0.7

Sample code

@Component
public class BatchCommandHandler {
private Repository repository;
@CommandHandler
public void handleCreateBatch(CreateBatchCommand command) {
Batch batch = new Batch(command.getBatchId);
repository.add(batch);
}
@Autowired
@Qualifier(“batchRepository”)
public void setRepository(Repository batchRepository) {
this.repository = batchRepository;
}
}

<axon:event-sourcing-repository id=“batchRepository”
aggregate-type=“com.bayer.service.stock.domain.batch.Batch”
event-bus=“eventBus”
event-store=“eventStore”>
<axon:snapshotter-trigger event-count-threshold=“50” snapshotter-ref=“snapshotter”/>
</axon:event-sourcing-repository>

Hi Cliff,

they have changed the way Spring works with generics in 4.0.0. They now see generics as some form of qualifier.
When providing an explicit @Qualifier, does the proper repository get injected, or does it also fail in that case?

Cheers,

Allard

Hi Allard,

It still fails in that case.
Currently the only way to inject a repository is by leaving out the generics

This will work

@Autowired @Qualifier("batchRepository")
public void setRepository(Repository batchRepository) {
this.repository = batchRepository;
}

This wont work

`
@Autowired
@Qualifier(“batchRepository”)
public void setRepository(Repository batchRepository) {
this.repository = batchRepository;
}

`

Spring will complain that there is no bean of type Repository, wich is indeed to how spring 4.0.0 now handles reflection.

I can continue to work since it works without the generics, i just wanted to log this as an improvement for the framework :slight_smile:

Have you tried autowiring by name instead of by type -- using one of the other dependency injection annotations? I think we had to use @Resource("myRepositoryName"). @Autowired+@Qualifier is still auto wiring by type + a filter. So is @Inject+@Named.

-Peter

Hi Peter,

That did the trick,
Using @Resource works.
Thank you for the help