spring-modulith icon indicating copy to clipboard operation
spring-modulith copied to clipboard

EnablePersistentDomainEvents annotation can't be used

Open v3rm0n opened this issue 2 years ago • 5 comments
trafficstars

Looks like EnablePersistentDomainEvents will select EventPublicationConfiguration for import and at the same time EventPublicationAutoConfiguration extends EventPublicationConfiguration so if you add EnablePersistentDomainEvents annotation then the application fails to start

***************************
APPLICATION FAILED TO START
***************************

Description:

The bean 'eventPublicationRegistry', defined in class path resource [org/springframework/modulith/events/config/EventPublicationAutoConfiguration.class], could not be registered. A bean with that name has already been defined in class path resource [org/springframework/modulith/events/config/EventPublicationConfiguration.class] and overriding is disabled.

Action:

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

Workaround for now seems to be to either enable overriding or just not using the annotation and manually importing your EventPublicationConfigurationExtension and EventSerializationConfigurationExtension implementations.

v3rm0n avatar Nov 16 '23 12:11 v3rm0n

Can you elaborate on why you would want to use the annotation explicitly? It's a left-over from the times in which Spring Boot was not a mandatory dependency. There's no real use for that any more, except in our very own integration testing code.

odrotbohm avatar Jan 16 '24 21:01 odrotbohm

Ah ok, I couldn't figure out a better way to use spring-modulith-events without other parts of modulith project.

v3rm0n avatar Jan 17 '24 06:01 v3rm0n

Can you elaborate on what you were trying to do? spring-modulith-events is not an actual artifact but solely a parent project for the individual ones. I.e. it doesn't really make sense to want to use that one in particular.

odrotbohm avatar Jan 17 '24 07:01 odrotbohm

Actual modules I added were

implementation 'org.springframework.modulith:spring-modulith-events-core'
implementation 'org.springframework.modulith:spring-modulith-events-jackson'
implementation 'org.springframework.modulith:spring-modulith-events-jdbc'

My goal is to use the persistent events logic in our modular monolith project without using full spring modulith

v3rm0n avatar Jan 17 '24 09:01 v3rm0n

Just fyi not an issue for me personally anymore, since using full Modulith instead of events only is not an issue actually

v3rm0n avatar Jan 31 '24 18:01 v3rm0n