michael-simons / neo4j-migrations

Automated script runner aka "Migrations" for Neo4j. Inspired by Flyway.
https://michael-simons.github.io/neo4j-migrations/
Apache License 2.0
118 stars 23 forks source link

Questions: native compilation support for spring boot starter? #1081

Open Dimibe opened 1 year ago

Dimibe commented 1 year ago

Hello,

does the neo4j-migrations-spring-boot-starter work with graalvm native compilation?

If I add neo4j-migrations-spring-boot-starter:2.6.0 (also tested with version 2.5.3) to my dependencies without any further configuration the native compilation fails with the following error:

According to the contribution guidelines native compilation is supported. Do I have to make additional configurations or is native compilation not support for the spring-boot-starter?

I didn't found any other documentation other than the one in the contribution guidelines.

Thanks in advance.


org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'neo4jMigrationsInitializer': null
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1770) ~[graalvm-test:6.0.11]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:598) ~[graalvm-test:6.0.11]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:520) ~[graalvm-test:6.0.11]
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:326) ~[graalvm-test:6.0.11]
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[graalvm-test:6.0.11]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:324) ~[graalvm-test:6.0.11]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[graalvm-test:6.0.11]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:973) ~[graalvm-test:6.0.11]
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:942) ~[graalvm-test:6.0.11]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:608) ~[graalvm-test:6.0.11]
        at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:66) ~[graalvm-test:3.1.3]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:734) ~[graalvm-test:3.1.3]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:436) ~[graalvm-test:3.1.3]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:312) ~[graalvm-test:3.1.3]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) ~[graalvm-test:3.1.3]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) ~[graalvm-test:3.1.3]
        at com.example.graalvmtest.GraalvmTestApplication.main(GraalvmTestApplication.java:18) ~[graalvm-test:na]
Caused by: java.lang.ExceptionInInitializerError: null
        at nonapi.io.github.classgraph.classpath.ClasspathOrder.<clinit>(ClasspathOrder.java:79) ~[na:na]
        at nonapi.io.github.classgraph.classpath.ClasspathFinder.<init>(ClasspathFinder.java:171) ~[na:na]
        at io.github.classgraph.Scanner.<init>(Scanner.java:168) ~[na:na]
        at io.github.classgraph.ClassGraph.scanAsync(ClassGraph.java:1562) ~[na:na]
        at io.github.classgraph.ClassGraph.scanAsync(ClassGraph.java:1590) ~[na:na]
        at io.github.classgraph.ClassGraph.scan(ClassGraph.java:1615) ~[na:na]
        at io.github.classgraph.ClassGraph.scan(ClassGraph.java:1654) ~[na:na]
        at io.github.classgraph.ClassGraph.scan(ClassGraph.java:1667) ~[na:na]
        at ac.simons.neo4j.migrations.core.DefaultClasspathResourceScanner.scan(DefaultClasspathResourceScanner.java:38) ~[na:na]
        at ac.simons.neo4j.migrations.core.ResourceDiscoverer.scanClasspathLocations(ResourceDiscoverer.java:136) ~[na:na]
        at ac.simons.neo4j.migrations.core.ResourceDiscoverer.discover(ResourceDiscoverer.java:122) ~[na:na]
        at ac.simons.neo4j.migrations.core.DiscoveryService.lambda$findCallbacks$8(DiscoveryService.java:153) ~[na:na]
        at java.base@20.0.2/java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:273) ~[na:na]
        at java.base@20.0.2/java.util.AbstractList$RandomAccessSpliterator.forEachRemaining(AbstractList.java:722) ~[na:na]
        at java.base@20.0.2/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509) ~[graalvm-test:na]
        at java.base@20.0.2/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499) ~[graalvm-test:na]
        at java.base@20.0.2/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) ~[graalvm-test:na]
        at java.base@20.0.2/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[graalvm-test:na]
        at java.base@20.0.2/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682) ~[graalvm-test:na]
        at ac.simons.neo4j.migrations.core.DiscoveryService.findCallbacks(DiscoveryService.java:154) ~[na:na]
        at ac.simons.neo4j.migrations.core.Migrations.getCallbacks(Migrations.java:130) ~[graalvm-test:2.6.0]
        at ac.simons.neo4j.migrations.core.Migrations.invokeCallbacks(Migrations.java:633) ~[graalvm-test:2.6.0]
        at ac.simons.neo4j.migrations.core.Migrations.executeWithinLock(Migrations.java:604) ~[graalvm-test:2.6.0]
        at ac.simons.neo4j.migrations.core.Migrations.apply(Migrations.java:222) ~[graalvm-test:2.6.0]
        at ac.simons.neo4j.migrations.springframework.boot.autoconfigure.MigrationsInitializer.afterPropertiesSet(MigrationsInitializer.java:45) ~[graalvm-test:na]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1817) ~[graalvm-test:6.0.11]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1766) ~[graalvm-test:6.0.11]
michael-simons commented 1 year ago

I didn't try to use Migrations in a Spring Boot native scenario, tbh. We have dedicated support for Quarkus in native mode and from your report it seems that is necessary for Spring Boot as well.

Dimibe commented 1 year ago

Thanks for the information, appreciate the quick reply.

michael-simons commented 1 year ago

I'm happy to invest sometime into this the upcoming week, but don't expect a quick solution.

Personally, I recommend having a look at the native neo4j-migration binary, especially if you are only dealing with

While it does not support Java based migrations, you will gain independence of the running application and also do this independent of how many instances of the app you are planning to run. Also, the Java based non-native package would support Java based migrations, if you want that.

So, a valid scenario could be

Dimibe commented 1 year ago

Thanks again for your detailed answer. Your recommendation seems to fit my use case very well. I have changed my project setup as you recommended and everything works great 👍

michael-simons commented 1 year ago

Great to hear, Dimitrios and thanks for your feedback!

I'd like to keep this open here nevertheless, I know it will bug me :)