Separating command from query in the spring boot CQRS projects(Multi module)

Hello
I want to split a spring boot CQRS project into three projects: 1- Command project 2- Query project 3- Core project(which contains the models and events).
All of these projects are defined as modules of a parent maven project(with POM packaging type).
To access to the core project from the command and query project in order to access to the models, I use this:

@EntityScan(basePackages = {
“com.his.patient.core.*”,
“org.axonframework.eventsourcing.eventstore.jpa”,
“org.axonframework.eventhandling.saga.repository.jpa”,
“org.axonframework.eventhandling.tokenstore”
})
But I get these messages:
Error occurred. Starting retry mode.
Fetched token: null for segment: Segment[0/0]
The versions I use are:
Spring boot :3.2.2
Axon framework: 4.9.3
When I do not use multi module way and I put all these three projects into one project, It works fine.

Thanks in advance for your help

It might be that you should drop the * here. If that doesn’t help, could you share any stacktraces that you find in the logs. They usually give much more information.

1 Like

Thank you for response.
This is the full stacktrace:

2024-03-19T15:27:25.627+03:30  INFO 20536 --- [patient_query_ms] [           main] c.h.p.PatientQueryMsApplication          : Starting PatientQueryMsApplication using Java 17.0.7 with PID 20536 (D:\patient-service\patient-management\patient_query_ms\target\classes started by Venos46131105 in D:\patient-service\patient-management)
2024-03-19T15:27:25.630+03:30  INFO 20536 --- [patient_query_ms] [           main] c.h.p.PatientQueryMsApplication          : No active profile set, falling back to 1 default profile: "default"
2024-03-19T15:27:25.799+03:30  WARN 20536 --- [patient_query_ms] [           main] o.s.c.annotation.AnnotationTypeMapping   : Support for convention-based annotation attribute overrides is deprecated and will be removed in Spring Framework 6.2. Please annotate the following attributes in @org.axonframework.eventhandling.EventHandler with appropriate @AliasFor declarations: [payloadType]
2024-03-19T15:27:25.803+03:30  WARN 20536 --- [patient_query_ms] [           main] o.s.c.annotation.AnnotationTypeMapping   : Support for convention-based annotation attribute overrides is deprecated and will be removed in Spring Framework 6.2. Please annotate the following attributes in @org.axonframework.messaging.interceptors.ExceptionHandler with appropriate @AliasFor declarations: [messageType, payloadType]
2024-03-19T15:27:26.442+03:30  INFO 20536 --- [patient_query_ms] [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2024-03-19T15:27:26.522+03:30  INFO 20536 --- [patient_query_ms] [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 73 ms. Found 1 JPA repository interface.
2024-03-19T15:27:27.266+03:30  INFO 20536 --- [patient_query_ms] [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port 8081 (http)
2024-03-19T15:27:27.282+03:30  INFO 20536 --- [patient_query_ms] [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2024-03-19T15:27:27.283+03:30  INFO 20536 --- [patient_query_ms] [           main] o.apache.catalina.core.StandardEngine    : Starting Servlet engine: [Apache Tomcat/10.1.18]
2024-03-19T15:27:27.354+03:30  INFO 20536 --- [patient_query_ms] [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2024-03-19T15:27:27.355+03:30  INFO 20536 --- [patient_query_ms] [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1671 ms
2024-03-19T15:27:27.561+03:30  INFO 20536 --- [patient_query_ms] [           main] org.hibernate.Version                    : HHH000412: Hibernate ORM core version 6.4.1.Final
2024-03-19T15:27:27.590+03:30  INFO 20536 --- [patient_query_ms] [           main] o.h.c.internal.RegionFactoryInitiator    : HHH000026: Second-level cache disabled
2024-03-19T15:27:27.824+03:30  INFO 20536 --- [patient_query_ms] [           main] o.s.o.j.p.SpringPersistenceUnitInfo      : No LoadTimeWeaver setup: ignoring JPA class transformer
2024-03-19T15:27:27.849+03:30  INFO 20536 --- [patient_query_ms] [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2024-03-19T15:27:28.122+03:30  INFO 20536 --- [patient_query_ms] [           main] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Added connection com.mysql.cj.jdbc.ConnectionImpl@aee05f4
2024-03-19T15:27:28.124+03:30  INFO 20536 --- [patient_query_ms] [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2024-03-19T15:27:28.166+03:30  WARN 20536 --- [patient_query_ms] [           main] org.hibernate.orm.deprecation            : HHH90000025: MySQL8Dialect does not need to be specified explicitly using 'hibernate.dialect' (remove the property setting and it will be selected by default)
2024-03-19T15:27:28.167+03:30  WARN 20536 --- [patient_query_ms] [           main] org.hibernate.orm.deprecation            : HHH90000026: MySQL8Dialect has been deprecated; use org.hibernate.dialect.MySQLDialect instead
2024-03-19T15:27:29.122+03:30  INFO 20536 --- [patient_query_ms] [           main] o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000489: No JTA platform available (set 'hibernate.transaction.jta.platform' to enable JTA platform integration)
Hibernate: create table dead_letter_entry (dead_letter_id varchar(255) not null, cause_message varchar(1023), cause_type varchar(255), diagnostics blob, enqueued_at datetime(6) not null, last_touched datetime(6), aggregate_identifier varchar(255), event_identifier varchar(255) not null, message_type varchar(255) not null, meta_data blob, payload blob not null, payload_revision varchar(255), payload_type varchar(255) not null, sequence_number bigint, time_stamp varchar(255) not null, token blob, token_type varchar(255), type varchar(255), processing_group varchar(255) not null, processing_started datetime(6), sequence_identifier varchar(255) not null, sequence_index bigint not null, primary key (dead_letter_id)) engine=InnoDB
Hibernate: create index IDXe67wcx5fiq9hl4y4qkhlcj9cg on dead_letter_entry (processing_group)
Hibernate: create index IDXrwucpgs6sn93ldgoeh2q9k6bn on dead_letter_entry (processing_group, sequence_identifier)
Hibernate: alter table dead_letter_entry drop index UKhlr8io86j74qy298xf720n16v
Hibernate: alter table dead_letter_entry add constraint UKhlr8io86j74qy298xf720n16v unique (processing_group, sequence_identifier, sequence_index)
2024-03-19T15:27:29.329+03:30  INFO 20536 --- [patient_query_ms] [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2024-03-19T15:27:29.457+03:30  INFO 20536 --- [patient_query_ms] [           main] o.a.s.a.XStreamAutoConfiguration         : Initializing an XStream instance since none was found. The auto configuration base packages will be used as wildcards for the XStream security settings.
2024-03-19T15:27:29.592+03:30  INFO 20536 --- [patient_query_ms] [           main] o.a.s.util.XStreamSecurityTypeUtility    : Constructing wildcard type for base package [com.his.patient_query_ms].
2024-03-19T15:27:29.592+03:30  INFO 20536 --- [patient_query_ms] [           main] o.a.s.util.XStreamSecurityTypeUtility    : Constructing wildcard type for base package [org.axonframework.eventhandling.tokenstore].
2024-03-19T15:27:29.592+03:30  INFO 20536 --- [patient_query_ms] [           main] o.a.s.util.XStreamSecurityTypeUtility    : Constructing wildcard type for base package [org.axonframework.eventhandling.deadletter.jpa].
2024-03-19T15:27:29.592+03:30  INFO 20536 --- [patient_query_ms] [           main] o.a.s.util.XStreamSecurityTypeUtility    : Constructing wildcard type for base package [org.axonframework.modelling.saga.repository.jpa].
2024-03-19T15:27:29.601+03:30  INFO 20536 --- [patient_query_ms] [           main] o.a.serialization.ChainingConverter      : ContentTypeConverter of type [class org.axonframework.serialization.xml.Dom4JToByteArrayConverter] is ignored. It seems to rely on a class that is not available in the class loader: org/dom4j/Document
2024-03-19T15:27:29.602+03:30  INFO 20536 --- [patient_query_ms] [           main] o.a.serialization.ChainingConverter      : ContentTypeConverter of type [class org.axonframework.serialization.xml.InputStreamToDom4jConverter] is ignored. It seems to rely on a class that is not available in the class loader: org/dom4j/Document
2024-03-19T15:27:29.603+03:30  INFO 20536 --- [patient_query_ms] [           main] o.a.serialization.ChainingConverter      : ContentTypeConverter of type [class org.axonframework.serialization.xml.XomToStringConverter] is ignored. It seems to rely on a class that is not available in the class loader: nu/xom/Document
2024-03-19T15:27:29.603+03:30  INFO 20536 --- [patient_query_ms] [           main] o.a.serialization.ChainingConverter      : ContentTypeConverter of type [class org.axonframework.serialization.xml.InputStreamToXomConverter] is ignored. It seems to rely on a class that is not available in the class loader: nu/xom/ParsingException
2024-03-19T15:27:29.646+03:30  INFO 20536 --- [patient_query_ms] [           main] o.a.config.AxonIQConsoleModule           :
2024-03-19T15:27:30.019+03:30  WARN 20536 --- [patient_query_ms] [           main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2024-03-19T15:27:30.392+03:30  INFO 20536 --- [patient_query_ms] [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port 8081 (http) with context path ''
2024-03-19T15:27:30.654+03:30  INFO 20536 --- [patient_query_ms] [           main] i.a.a.c.impl.AxonServerManagedChannel    : Requesting connection details from localhost:8124
2024-03-19T15:27:30.870+03:30  INFO 20536 --- [patient_query_ms] [           main] i.a.a.c.impl.AxonServerManagedChannel    : Successfully connected to localhost:8124
2024-03-19T15:27:30.878+03:30  INFO 20536 --- [patient_query_ms] [           main] i.a.a.connector.impl.ControlChannelImpl  : Connected instruction stream for context 'default'. Sending client identification
2024-03-19T15:27:30.900+03:30  INFO 20536 --- [patient_query_ms] [           main] i.a.a.c.query.impl.QueryChannelImpl      : QueryChannel for context 'default' connected, 0 registrations resubscribed
2024-03-19T15:27:30.906+03:30  INFO 20536 --- [patient_query_ms] [           main] i.a.a.c.query.impl.QueryChannelImpl      : Registered handler for query 'com.his.patient.core.queries.FindPatientByPersonalIdQuery : com.his.patient_query_ms.responeObj.PatientResponse' in context 'default'
Hibernate: select te1_0.processor_name,te1_0.segment,te1_0.owner,te1_0.timestamp,te1_0.token,te1_0.token_type from token_entry te1_0 where (te1_0.processor_name,te1_0.segment) in ((?,?))
2024-03-19T15:27:31.002+03:30  INFO 20536 --- [patient_query_ms] [           main] c.h.p.PatientQueryMsApplication          : Started PatientQueryMsApplication in 5.833 seconds (process running for 6.275)
Hibernate: select te1_0.segment from token_entry te1_0 where te1_0.processor_name=? order by te1_0.segment
Hibernate: select te1_0.processor_name,te1_0.segment,te1_0.owner,te1_0.timestamp,te1_0.token,te1_0.token_type from token_entry te1_0 where te1_0.processor_name=? order by te1_0.segment
Hibernate: select te1_0.processor_name,te1_0.segment,te1_0.owner,te1_0.timestamp,te1_0.token,te1_0.token_type from token_entry te1_0 where (te1_0.processor_name,te1_0.segment) in ((?,?)) for update
Hibernate: select te1_0.processor_name,te1_0.segment,te1_0.owner,te1_0.timestamp,te1_0.token,te1_0.token_type from token_entry te1_0 where (te1_0.processor_name,te1_0.segment) in ((?,?)) for update
2024-03-19T15:27:31.191+03:30  INFO 20536 --- [patient_query_ms] [atient-group]-0] o.a.e.TrackingEventProcessor             : Worker assigned to segment Segment[0/0] for processing
Hibernate: update token_entry set owner=?,timestamp=?,token=?,token_type=? where processor_name=? and segment=?
2024-03-19T15:27:31.211+03:30  INFO 20536 --- [patient_query_ms] [atient-group]-0] o.a.e.TrackingEventProcessor             : Using current Thread for last segment worker: TrackingSegmentWorker{processor=patient-group, segment=Segment[0/0]}
Hibernate: select te1_0.processor_name,te1_0.segment,te1_0.owner,te1_0.timestamp,te1_0.token,te1_0.token_type from token_entry te1_0 where (te1_0.processor_name,te1_0.segment) in ((?,?)) for update
Hibernate: update token_entry set owner=?,timestamp=?,token=?,token_type=? where processor_name=? and segment=?
2024-03-19T15:27:31.223+03:30  INFO 20536 --- [patient_query_ms] [atient-group]-0] o.a.e.TrackingEventProcessor             : Fetched token: null for segment: Segment[0/0]


com.thoughtworks.xstream.security.ForbiddenClassException: com.his.patient.core.event.NewPatientCreatedEvent
at com.thoughtworks.xstream.security.NoTypePermission.allows(NoTypePermission.java:26) ~[xstream-1.4.20.jar:1.4.20]
at com.thoughtworks.xstream.mapper.SecurityMapper.realClass(SecurityMapper.java:74) ~[xstream-1.4.20.jar:1.4.20]
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:125) ~[xstream-1.4.20.jar:1.4.20]
at com.thoughtworks.xstream.mapper.CachingMapper.realClass(CachingMapper.java:47) ~[xstream-1.4.20.jar:1.4.20]
at org.axonframework.serialization.AbstractXStreamSerializer.classForType(AbstractXStreamSerializer.java:171) ~[axon-messaging-4.9.2.jar:4.9.2]
at org.axonframework.axonserver.connector.event.axon.GrpcMetaDataAwareSerializer.classForType(GrpcMetaDataAwareSerializer.java:75) ~[axon-server-connector-4.9.2.jar:4.9.2]
at org.axonframework.serialization.LazyDeserializingObject.<init>(LazyDeserializingObject.java:83) ~[axon-messaging-4.9.2.jar:4.9.2]
at org.axonframework.eventhandling.EventUtils.lambda$upcastAndDeserializeTrackedEvents$1(EventUtils.java:107) ~[axon-messaging-4.9.2.jar:4.9.2]
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197) ~[na:na]
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197) ~[na:na]
at org.axonframework.axonserver.connector.event.axon.EventBuffer$SimpleSpliterator.tryAdvance(EventBuffer.java:216) ~[axon-server-connector-4.9.2.jar:4.9.2]
at java.base/java.util.stream.StreamSpliterators$WrappingSpliterator.lambda$initPartialTraversalState$0(StreamSpliterators.java:292) ~[na:na]
at java.base/java.util.stream.StreamSpliterators$AbstractWrappingSpliterator.fillBuffer(StreamSpliterators.java:206) ~[na:na]
at java.base/java.util.stream.StreamSpliterators$AbstractWrappingSpliterator.doAdvance(StreamSpliterators.java:169) ~[na:na]
at java.base/java.util.stream.StreamSpliterators$WrappingSpliterator.tryAdvance(StreamSpliterators.java:298) ~[na:na]
at java.base/java.util.Spliterators$1Adapter.hasNext(Spliterators.java:681) ~[na:na]
at org.axonframework.axonserver.connector.event.axon.EventBuffer.peekNullable(EventBuffer.java:171) ~[axon-server-connector-4.9.2.jar:4.9.2]
at org.axonframework.axonserver.connector.event.axon.EventBuffer.hasNextAvailable(EventBuffer.java:144) ~[axon-server-connector-4.9.2.jar:4.9.2]
at org.axonframework.eventhandling.TrackingEventProcessor.processBatch(TrackingEventProcessor.java:419) ~[axon-messaging-4.9.2.jar:4.9.2]
at org.axonframework.eventhandling.TrackingEventProcessor.processingLoop(TrackingEventProcessor.java:316) ~[axon-messaging-4.9.2.jar:4.9.2]
at org.axonframework.eventhandling.TrackingEventProcessor$TrackingSegmentWorker.run(TrackingEventProcessor.java:1200) ~[axon-messaging-4.9.2.jar:4.9.2]
at org.axonframework.eventhandling.TrackingEventProcessor$WorkerLauncher.cleanUp(TrackingEventProcessor.java:1402) ~[axon-messaging-4.9.2.jar:4.9.2]
at org.axonframework.eventhandling.TrackingEventProcessor$WorkerLauncher.run(TrackingEventProcessor.java:1379) ~[axon-messaging-4.9.2.jar:4.9.2]
at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]


2024-03-19T15:27:31.257+03:30  WARN 20536 --- [patient_query_ms] [atient-group]-0] o.a.e.TrackingEventProcessor             : Releasing claim on token and preparing for retry in 1s
Hibernate: update token_entry set owner=null where owner=? and processor_name=? and segment=?
2024-03-19T15:27:31.298+03:30  INFO 20536 --- [patient_query_ms] [atient-group]-0] o.a.e.TrackingEventProcessor             : Released claim
Hibernate: select te1_0.processor_name,te1_0.segment,te1_0.owner,te1_0.timestamp,te1_0.token,te1_0.token_type from token_entry te1_0 where (te1_0.processor_name,te1_0.segment) in ((?,?)) for update
Hibernate: update token_entry set owner=?,timestamp=?,token=?,token_type=? where processor_name=? and segment=?
2024-03-19T15:27:32.314+03:30  INFO 20536 --- [patient_query_ms] [atient-group]-0] o.a.e.TrackingEventProcessor             : Fetched token: null for segment: Segment[0/0]
2024-03-19T15:27:32.320+03:30  WARN 20536 --- [patient_query_ms] [atient-group]-0] o.a.e.TrackingEventProcessor             : Releasing claim on token and preparing for retry in 2s

It seems like it’s an issue with the XSTream serialiser. Can you set property axon.serializer.general to jackson? This will move the default serializer to Jackson, which is more friendly, especially with newer Java version and using classes not in the same project. Alternatively, you might need to set some flags to make it work with XStream.

1 Like

It worked. Thank you so much