Bean Conflict with JmixDataRepositories

Hi platform team,

Using SpringData Elasticsearch, I had the implementation of ElasticsearchRepository to communicate with an ElasticSearch API and it was working fine earlier. But after upgrade to Jmix version, it’s throwing the exception below.


APPLICATION FAILED TO START


Description:

The bean ‘ESAuditLogRepo’, defined in service.elasticsearch.ESAuditLogRepo defined in @EnableElasticsearchRepositories declared on ElasticsearchRepositoriesRegistrar.EnableElasticsearchRepositoriesConfiguration, could not be registered. A bean with that name has already been defined in service.elasticsearch.ESAuditLogRepo defined in @EnableJmixDataRepositories declared on BootJmixRepositoriesRegistrar.EnableJmixDataRepositoriesConfiguration and overriding is disabled.

Action:

Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true

I already figured out the root cause my self. Spring takes care of the bean creation based on the declaration of the 2 annotation: EnableElasticsearchRepositories and EnableJmixDataRepositories
Look like Jmix also tried to scan all the Spring repo interface and instantiate the bean then lead to the conflict.

Googled around and found 2 solution so far:
1/ Allow bean overriding by

spring.main.allow-bean-definition-overriding=true

2/ Try to exclude the package like:

@EnableJmixDataRepositories(excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = ESAuditLogRepo.class))

I don’t know well how the DataRepositories implemented internally inside Jmix, need to consult from JMIX team on which would be a better approach.

And is it possible for Jmix to just scan all the Repo defined by Jmix core or at least a configurable flag to do so?

Hope to hear from team soon. Thanks

Hi Nghia,

Jmix DataRepositories is optional functionality, so If you don’t need them in your project, you can just disable them by adding
jmix.core.dataRepositories.enabled=false
to ‘application.properties’.

If you want to use different repository types at the same time, it is better to put different repositories to different packages and specify these packages using @Enable...Repository annotation, so solutions like (2) is preferable.

Bean overriding may lead to wrong repository type and wrong behaviour.

Regards,
Dmitry

Thanks @taimanov.

I thought the Jmix DataRepositories were to implement the core JPA Repositories and maybe used for dataManager and other DB communication.

The problem was I couldn’t tell Jmix to exclude my own repository located at a different package like u said. Sound like the bean override is not a good approach. I’ll try to disable the JMIX DataRepositories to see if that works

@taimanov , tried your suggestion to disable Jmix core repo and that works. Thanks much for your support.