Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to create Spring native image #538

Open
KevinGuancheDarias opened this issue Feb 11, 2024 · 0 comments
Open

Not able to create Spring native image #538

KevinGuancheDarias opened this issue Feb 11, 2024 · 0 comments

Comments

@KevinGuancheDarias
Copy link
Owner

KevinGuancheDarias commented Feb 11, 2024

As of commit: (a0ca18f) The following applies

Won't be able for now to create a Spring Boot Native image due to lack of support for @lazy annotation, which is extensively used to allow creating spring context aware jpa entity listeners, not using lazy would cause a circular ref, because the entity listener needs repositories which needs entityManager, which needs entityListeners

The following exception is thrown
image

Note that even if running in jvm by using the intellij to run the app as normal, it will fail, because the native image builder generates and places its aot processed classes in target/classes folder, which would then be read by the regular compile process of IntelliJ

The error happends exactly here:
image
It tries to build the proxy instance for ObjectRelationBo which is lazyly-required by EntityWithRelationListener

Note that even if the Spring team fixes the bug, it may be worth nothing that maybe it wouldn't here anyway, because, lazies would be resolved at compiled time, and maybe it wouldn't be able to handle circular reference, as it has been init all together at the same time (or maybe yes, if they use a metadata structure to handle circular refs just like ts-lollipop does)

Some work still pending on branch tmp/experiment-native-image (commit: e975f7f)

Track issue spring-projects/spring-framework#30985

Remember: Run the agent with graalvm to find out at runtime possible dynamic content (used for example to find out required classes for aspectj

java -agentlib:native-image-agent=config-output-dir=src/main/resources/META-INF/native-image -jar target/owgejava-game-rest.jar

Command to launch native image in local

 docker run --rm -p 8080:8080 --env OWGE_DB_URL='192.168.1.253:3306/owge_dev' --env OWGE_DB_USER=root --env OWGE_DB_PASS=1234  docker.io/library/game-rest:0.11.5-SNAPSHOT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant