spring-projects / spring-projects/spring-modulith

Issues I encountered when using Spring Modulith

Open
#311 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
1.2k
Forks
222
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the reported behavior with spring-modulith-starter-jpa, spring-modulith-events-core, and @EnablePersistentDomainEvents. Investigate the named AggregateChangeEventExecutorConfiguration, JpaEventPublication, @EntityScan, and @Async @TransactionalEventListener cases separately. Done means each issue has a confirmed scope, an identified cause, and tests or documented behavior for the relevant fix.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring, spring-boot
Domain
backend, database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.