spring-projects / spring-modulith

Modular applications with Spring Boot
https://spring.io/projects/spring-modulith
Apache License 2.0
811 stars 139 forks source link

Issues I encountered when using Spring Modulith #311

Open MarkLehmacherInvestify opened 1 year ago

MarkLehmacherInvestify commented 1 year ago

Hi there,

I investigated Spring Modulith, because it exactly fits my organisation's approach to organically growing a microservice architecture. Thank you very much for your work on Spring Modulith!

My first use case was to get @EnablePersistentDomainEvents working. To that end I included dependencies for spring-modulith-starter-jpa and spring-modulith-events-core (trying both 1.0.1 and 1.1.0-M1).

During my evaluation I encountered the following issues.

BeanDefinitionOverrideException: Invalid bean definition with name 'aggregateChangeEventHandle

org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'aggregateChangeEventHandler' defined in class path resource [com/investify/product/bc_robo_advisor/change_management/configuration/AggregateChangeEventExecutorConfiguration.class]: Cannot register bean definition [Root bean: class [null]; scope=; abstract=false; lazyInit=null; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=aggregateChangeEventExecutorConfiguration; factoryMethodName=investmentLifecycleListenerTaskExecutor; initMethodNames=null; destroyMethodNames=[(inferred)]; defined in class path resource [com/investify/product/bc_robo_advisor/change_management/configuration/AggregateChangeEventExecutorConfiguration.class]] for bean 'aggregateChangeEventHandler' since there is already [Generic bean: class [com.investify.product.bc_robo_advisor.change_management.AggregateChangeEventHandler]; scope=singleton; abstract=false; lazyInit=null; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodNames=null; destroyMethodNames=null; defined in file [/Users/mlehmacher/Develop/investify-components/hybrid-onboarding/service/build/classes/java/main/com/investify/product/bc_robo_advisor/change_management/AggregateChangeEventHandler.class]] bound.

I don't know why this happens, my suspicion is the AutoConfiguration which extends the regular Configuration in combination with an AutoConfigurationPackage shrug

I wasn't able to fix this by any other way (Configuration exclusions, etc.) than generally allowing bean definition overrides: spring.main.allow-bean-definition-overriding: true

JpaEventPublication Entity wasn't picked up

Cause of this was an @EntityScan on our main application class. Apparently there is a known issue with @EntityScan causing side effects on Entity discovery of auto configuration packages.

I just removed @EntityScan from our application class as the default behavior works for us.

JpaEventPublication#serializedEvent does not allow serializations with more than 255 chars and my persistence provider throws an exception if longer values are encountered

This is mainly an issue for tests. For production usage we can take care of serializedEvent allowing more chars by way of liquibase schema management.

As a workaround I duplicated org.springframework.modulith.events.jpa.JpaEventPublication into my the service source tree and added a @Column(length = 8000 ) annotation

AsyncUncaughtExceptionHandler not working with @Async @TransactionalEventListener when @EnablePersistentDomainEvents is active

My custom exception handler is never called when uncatched Exceptions are encountered within a @Async @TransactionalEventListener listener while @EnablePersistentDomainEvents is enabled. The custom exception handler gets called as soon as I disable persistent domain events.

odrotbohm commented 11 months ago

The last of the listed issues should be solved by the fix for GH-372.