spring-native
spring-native copied to clipboard
Add FreeMarker support
Hello
I just created a demo project from start.spring.io/, I have freemarker as dependency and one controller, not using freemarker yet. but getting error below when I ran the docker
2021-06-01 18:38:43.799 INFO 1 --- [ main] o.s.nativex.NativeListener : This application is bootstrapped with code generated with Spring AOT
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.5.0)
2021-06-01 18:38:43.800 INFO 1 --- [ main] com.example.demo.DemoApplication : Starting DemoApplication using Java 11.0.10 on bc6534630683 with PID 1 (/workspace/com.example.demo.DemoApplication started by cnb in /workspace)
2021-06-01 18:38:43.800 INFO 1 --- [ main] com.example.demo.DemoApplication : No active profile set, falling back to default profiles: default
2021-06-01 18:38:43.815 WARN 1 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [com.example.demo.DemoApplication]; nested exception is java.lang.IllegalStateException: Error processing condition on org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration
2021-06-01 18:38:43.816 INFO 1 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-06-01 18:38:43.816 ERROR 1 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to bind properties under 'spring.freemarker' to org.springframework.boot.autoconfigure.freemarker.FreeMarkerTemplateAvailabilityProvider$FreeMarkerTemplateAvailabilityProperties:
Reason: org.springframework.boot.autoconfigure.freemarker.FreeMarkerTemplateAvailabilityProvider$FreeMarkerTemplateAvailabilityProperties.<init>()
Action:
Update your application's configuration
I tried to exclude FreeMarkerAutoConfiguration, thought maybe that is the culprit but did not solve, any suggestions ? here is the reproducer:demo.tar.gz
Thanks
I tried adding a simple hint for that one, but freemarker is using a lot of reflection so it will require a bigger effort to be supported.
If you explain what to do? I or anyone who knows java can help ☺️
I would suggest to add native testing to https://github.com/apache/freemarker in a pull-request via https://github.com/graalvm/native-build-tools/ and craft native reflection config with the help of the tracing agent.
I check https://github.com/apache/freemarker and I saw it uses ant. anyway tried to build in my local it failed, then I decided to test with quarkus.https://github.com/ozkanpakdil/quarkus-examples/tree/master/freemarker this is the example project and I build native and run it in my local
mlinux@mint20:~/tmp/quarkus-examples/freemarker/target$ curl localhost:8080/hello?name=test222
Hello test222! mlinux@mint20:~/tmp/quarkus-examples/freemarker/target$
when I check the dependencies I see org freemarker 2.3.31

I think this is spring freemarker configuration problem not related to freemarker library graalvm issue, below you can find quarkus plugin graalvm parameters
[INFO] --- quarkus-maven-plugin:2.0.1.Final:build (default) @ code-with-quarkus ---
[INFO] [org.jboss.threads] JBoss Threads version 3.4.0.Final
[INFO] [io.quarkus.deployment.pkg.steps.JarResultBuildStep] Building native image source jar: /home/mlinux/tmp/quarkus-examples/freemarker/target/code-with-quarkus-1.0.0-SNAPSHOT-native-image-source-jar/code-with-quarkus-1.0.0-SNAPSHOT-runner.jar
[INFO] [io.quarkus.deployment.pkg.steps.NativeImageBuildStep] Building native image from /home/mlinux/tmp/quarkus-examples/freemarker/target/code-with-quarkus-1.0.0-SNAPSHOT-native-image-source-jar/code-with-quarkus-1.0.0-SNAPSHOT-runner.jar
[INFO] [io.quarkus.deployment.pkg.steps.NativeImageBuildStep] Running Quarkus native-image plugin on GraalVM 21.1.0 Java 11 CE (Java Version 11.0.11+8-jvmci-21.1-b05)
[INFO] [io.quarkus.deployment.pkg.steps.NativeImageBuildRunner] /usr/lib/jvm/graalvm-ce-java11-21.1.0/bin/native-image -J-Dsun.nio.ch.maxUpdateArraySize=100 -J-Djava.util.logging.manager=org.jboss.logmanager.LogManager -J-Dvertx.logger-delegate-factory-class-name=io.quarkus.vertx.core.runtime.VertxLogDelegateFactory -J-Dvertx.disableDnsResolver=true -J-Dio.netty.leakDetection.level=DISABLED -J-Dio.netty.allocator.maxOrder=3 -J-Duser.language=en -J-Duser.country=GB -J-Dfile.encoding=UTF-8 --initialize-at-build-time= -H:InitialCollectionPolicy=com.oracle.svm.core.genscavenge.CollectionPolicy\$BySpaceAndTime -H:+JNI -H:+AllowFoldMethods -jar code-with-quarkus-1.0.0-SNAPSHOT-runner.jar -H:FallbackThreshold=0 -H:+ReportExceptionStackTraces -H:-AddAllCharsets -H:EnableURLProtocols=http -H:NativeLinkerOption=-no-pie -H:-UseServiceLoaderFeature -H:+StackTrace code-with-quarkus-1.0.0-SNAPSHOT-runner
[code-with-quarkus-1.0.0-SNAPSHOT-runner:255621] classlist: 5,847.03 ms, 1.18 GB
[code-with-quarkus-1.0.0-SNAPSHOT-runner:255621] (cap): 1,074.63 ms, 1.18 GB
[code-with-quarkus-1.0.0-SNAPSHOT-runner:255621] setup: 4,251.76 ms, 1.18 GB
17:42:13,933 INFO [org.jbo.threads] JBoss Threads version 3.4.0.Final
[code-with-quarkus-1.0.0-SNAPSHOT-runner:255621] (clinit): 1,232.71 ms, 3.03 GB
[code-with-quarkus-1.0.0-SNAPSHOT-runner:255621] (typeflow): 39,857.46 ms, 3.03 GB
[code-with-quarkus-1.0.0-SNAPSHOT-runner:255621] (objects): 84,312.19 ms, 3.03 GB
[code-with-quarkus-1.0.0-SNAPSHOT-runner:255621] (features): 5,280.91 ms, 3.03 GB
[code-with-quarkus-1.0.0-SNAPSHOT-runner:255621] analysis: 133,903.36 ms, 3.03 GB
[code-with-quarkus-1.0.0-SNAPSHOT-runner:255621] universe: 3,710.30 ms, 3.03 GB
[code-with-quarkus-1.0.0-SNAPSHOT-runner:255621] (parse): 13,630.43 ms, 2.84 GB
[code-with-quarkus-1.0.0-SNAPSHOT-runner:255621] (inline): 27,180.70 ms, 4.19 GB
[code-with-quarkus-1.0.0-SNAPSHOT-runner:255621] (compile): 78,493.10 ms, 4.34 GB
[code-with-quarkus-1.0.0-SNAPSHOT-runner:255621] compile: 126,881.81 ms, 4.34 GB
[code-with-quarkus-1.0.0-SNAPSHOT-runner:255621] image: 15,247.00 ms, 4.31 GB
[code-with-quarkus-1.0.0-SNAPSHOT-runner:255621] write: 2,216.20 ms, 4.31 GB
# Printing build artifacts to: code-with-quarkus-1.0.0-SNAPSHOT-runner.build_artifacts.txt
[code-with-quarkus-1.0.0-SNAPSHOT-runner:255621] [total]: 293,256.33 ms, 4.31 GB
[INFO] [io.quarkus.deployment.pkg.steps.NativeImageBuildRunner] objcopy --strip-debug code-with-quarkus-1.0.0-SNAPSHOT-runner
[INFO] [io.quarkus.deployment.QuarkusAugmentor] Quarkus augmentation completed in 298692ms
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 05:13 min
[INFO] Finished at: 2021-07-07T17:46:04+01:00
[INFO] ------------------------------------------------------------------------
Spring configuration for Freemarker is 1 or 2 missing hints, not a big deal, but what requires more work is Freemarker native support, which should not be reimplemented in each framework supporting GraalVM native IMO. We will provide clearer guidance on how to do that later this year.
Spring Native is now superseded by Spring Boot 3 official native support, see the related reference documentation for more details.
As a consequence, I am closing this issue, and recommend trying your use case with latest Spring Boot 3 version. If you still experience the issue reported here, please open an issue directly on the GraalVM Reachability Repository project.
Thanks for your contribution on the experimental Spring Native project, we hope you will enjoy the official native support introduced by Spring Boot 3.