AxonFramework: Axon doesn't work in combination with spring-boot-dev-tools on class path

Axon version: 3.0.2 With: spring-boot-axon + H2 + No cache repository

If you add spring-boot-dev-tools in your class path, axon will not work. I am not sure, but spring-boot-dev-tools will change the path class name of event message object and during the publishing this event will not match.

I make an example here -> https://github.com/moifort/axon-sample-with-spring-dev-tools

Make the test by removing/adding spring-boot-dev-tools dependency

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 16 (9 by maintainers)

Commits related to this issue

Most upvoted comments

Did some test with the sample project given by @moifort The Axon jars are just one part, the serializer has to be included too. What finally worked:

restart.include.axon-core=axon-core-3.0.2.jar
restart.include.axon-spring=axon-spring-3.0.2.jar
restart.include.axon-spring-boot-autoconfigure=axon-spring-boot-autoconfigure-3.0.2.jar
restart.include.xstream=xstream-1.4.9.jar

Depending on the serializer chosen by the developer you have to include more dependencies (with unknown side effects). I think this should not be handled by Axon. Just add a section to the README and give some examples for common use cases.

We’ve prioritized a fix/solution for the spring-dev-tools issue in #1382 for release 4.4. That issue links to the majority of the created issues around spring-dev-tools, although I forget to reference this one; sorry for that unclarity.

By the way, the file you’re referencing was intended as a fix for the users, although it indeed doesn’t work as expected.

I removed spring-boot-devtools from my pom.xml this is also working for me in production. Thanks a lot 😃

Seems like this can be resolved without touching XStream. There are multiple locations involved:

The JpaEventStorageEngine in JpaConfiguration is constructed without the Serializer Bean:

https://github.com/AxonFramework/AxonFramework/blob/master/spring-boot-autoconfigure/src/main/java/org/axonframework/boot/AxonAutoConfiguration.java#L173

The XStream instance of the XStreamSerializer is configured without a classLoader. So the ClassLoader of the library is used.

A working example is:

Add to spring-devtools.properties:

restart.include.axon-core=axon-core-3.0.2.jar
restart.include.axon-spring=axon-spring-3.0.2.jar
restart.include.axon-spring-boot-autoconfigure=axon-spring-boot-autoconfigure-3.0.2.jar

Add a configuration class:

    @Configuration
    public static class AxonConfiguration {

        @Bean
        public Serializer serializer() {
            final XStream xStream = new XStream(new CompactDriver());
            xStream.setClassLoader(this.getClass().getClassLoader());
            final XStreamSerializer serializer = new XStreamSerializer(xStream);

            return serializer;
        }

        @Bean
        public EventStorageEngine eventStorageEngine(Serializer serializer, EntityManagerProvider entityManagerProvider, TransactionManager transactionManager) {
            JpaEventStorageEngine engine = new JpaEventStorageEngine(serializer, null, null, null, entityManagerProvider, transactionManager, null, null, true);

            return engine;
        }

    }

This solves the issues at least for XStream without adding the lib to devtools. Seems like Jackson provides an explicity ClassLoader too.

Does anybody know how to unit test such class loader related stuff?