Use spring-cloud-config-server and config spring.cloud.config.server.bootstrap=true and compile it to native cloud-config-server code example
$> ./mvnw native:compile -Pnative
user@user ~/Downloads/cloud-config-server ./mvnw native:compile -Pnative ✓ 10009 11:49:23 [INFO] Scanning for projects... [INFO] [INFO] ------------------< com.example:cloud-config-server >------------------- [INFO] Building cloud-config-server 0.0.1-SNAPSHOT [INFO] --------------------------------[ jar ]--------------------------------- [INFO] [INFO] >>> native-maven-plugin:0.9.19:compile (default-cli) > package @ cloud-config-server >>> [INFO] [INFO] --- native-maven-plugin:0.9.19:add-reachability-metadata (add-reachability-metadata) @ cloud-config-server --- [INFO] [graalvm reachability metadata repository for org.apache.tomcat.embed:tomcat-embed-core:10.1.4]: Configuration directory not found. Trying latest version. [INFO] [graalvm reachability metadata repository for org.apache.tomcat.embed:tomcat-embed-core:10.1.4]: Configuration directory is org.apache.tomcat.embed/tomcat-embed-core/10.0.20 [INFO] [graalvm reachability metadata repository for org.hibernate.validator:hibernate-validator:8.0.0.Final]: Configuration directory not found. Trying latest version. [INFO] [graalvm reachability metadata repository for org.hibernate.validator:hibernate-validator:8.0.0.Final]: Configuration directory is org.hibernate.validator/hibernate-validator/7.0.4.Final [INFO] [graalvm reachability metadata repository for org.jboss.logging:jboss-logging:3.5.0.Final]: Configuration directory is org.jboss.logging/jboss-logging/3.5.0.Final [INFO] [graalvm reachability metadata repository for ch.qos.logback:logback-classic:1.4.5]: Configuration directory not found. Trying latest version. [INFO] [graalvm reachability metadata repository for ch.qos.logback:logback-classic:1.4.5]: Configuration directory is ch.qos.logback/logback-classic/1.4.1 [INFO] [INFO] --- maven-resources-plugin:3.3.0:resources (default-resources) @ cloud-config-server --- [INFO] Copying 1 resource [INFO] Copying 0 resource [INFO] [INFO] --- maven-compiler-plugin:3.10.1:compile (default-compile) @ cloud-config-server --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] --- maven-resources-plugin:3.3.0:testResources (default-testResources) @ cloud-config-server --- [INFO] skip non existing resourceDirectory /Users/user/Downloads/cloud-config-server/src/test/resources [INFO] [INFO] --- maven-compiler-plugin:3.10.1:testCompile (default-testCompile) @ cloud-config-server --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ cloud-config-server --- [INFO] [INFO] ------------------------------------------------------- [INFO] T E S T S [INFO] ------------------------------------------------------- [INFO] Running com.example.cloudconfigserver.CloudConfigServerApplicationTests 11:49:33.392 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Neither @ContextConfiguration nor @ContextHierarchy found for test class [CloudConfigServerApplicationTests]: using SpringBootContextLoader 11:49:33.411 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Could not detect default resource locations for test class [com.example.cloudconfigserver.CloudConfigServerApplicationTests]: no resource found for suffixes {-context.xml, Context.groovy}. 11:49:33.412 [main] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils - Could not detect default configuration classes for test class [com.example.cloudconfigserver.CloudConfigServerApplicationTests]: CloudConfigServerApplicationTests does not declare any static, non-private, non-final, nested classes annotated with @Configuration. 11:49:33.488 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Using ContextCustomizers for test class [CloudConfigServerApplicationTests]: [ExcludeFilterContextCustomizer, DuplicateJsonObjectContextCustomizer, MockitoContextCustomizer, TestRestTemplateContextCustomizer, DisableObservabilityContextCustomizer, PropertyMappingContextCustomizer, Customizer] 11:49:33.854 [main] DEBUG org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider - Identified candidate component class: file [/Users/user/Downloads/cloud-config-server/target/classes/com/example/cloudconfigserver/CloudConfigServerApplication.class] 11:49:33.856 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Found @SpringBootConfiguration com.example.cloudconfigserver.CloudConfigServerApplication for test class com.example.cloudconfigserver.CloudConfigServerApplicationTests 11:49:34.079 [main] DEBUG org.springframework.test.context.util.TestContextSpringFactoriesUtils - Skipping candidate TestExecutionListener [org.springframework.test.context.transaction.TransactionalTestExecutionListener] due to a missing dependency. Specify custom TestExecutionListener classes or make the default TestExecutionListener classes and their required dependencies available. Offending class: [org/springframework/transaction/interceptor/TransactionAttributeSource] 11:49:34.081 [main] DEBUG org.springframework.test.context.util.TestContextSpringFactoriesUtils - Skipping candidate TestExecutionListener [org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener] due to a missing dependency. Specify custom TestExecutionListener classes or make the default TestExecutionListener classes and their required dependencies available. Offending class: [org/springframework/transaction/interceptor/TransactionAttribute] 11:49:34.084 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Using TestExecutionListeners for test class [CloudConfigServerApplicationTests]: [ServletTestExecutionListener, DirtiesContextBeforeModesTestExecutionListener, ApplicationEventsTestExecutionListener, MockitoTestExecutionListener, DependencyInjectionTestExecutionListener, DirtiesContextTestExecutionListener, EventPublishingTestExecutionListener, ResetMocksTestExecutionListener, RestDocsTestExecutionListener, MockRestServiceServerResetTestExecutionListener, MockMvcPrintOnlyOnFailureTestExecutionListener, WebDriverTestExecutionListener, MockWebServiceServerTestExecutionListener] 11:49:34.086 [main] DEBUG org.springframework.test.context.support.AbstractDirtiesContextTestExecutionListener - Before test class: class [CloudConfigServerApplicationTests], class annotated with @DirtiesContext [false] with mode [null]
. _ _ __ _ _ /\ / ' __ _ () __ __ _ \ \ \ \ ( ( )_ | ' | '| | ' \/ _` | \ \ \ \ \/ )| |)| | | | | || (| | ) ) ) ) ' |_| .|| ||| |_, | / / / / =========|_|==============|/=//// :: Spring Boot :: (v3.0.1)
2023-01-19T11:49:34.653+08:00 INFO 87641 --- [ main] c.e.c.CloudConfigServerApplicationTests : Starting CloudConfigServerApplicationTests using Java 17.0.5 with PID 87641 (started by user in /Users/user/Downloads/cloud-config-server) 2023-01-19T11:49:34.655+08:00 INFO 87641 --- [ main] c.e.c.CloudConfigServerApplicationTests : No active profile set, falling back to 1 default profile: "default" 2023-01-19T11:49:37.218+08:00 INFO 87641 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=fa92d54c-f032-392a-a2d6-655a5e9ad163 2023-01-19T11:49:39.170+08:00 INFO 87641 --- [ main] c.e.c.CloudConfigServerApplicationTests : Started CloudConfigServerApplicationTests in 5.01 seconds (process running for 6.855) [INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 7.541 s - in com.example.cloudconfigserver.CloudConfigServerApplicationTests [INFO] [INFO] Results: [INFO] [INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 [INFO] [INFO] [INFO] --- spring-boot-maven-plugin:3.0.1:process-aot (process-aot) @ cloud-config-server ---
. _ _ __ _ _ /\ / ' __ _ () __ __ _ \ \ \ \ ( ( )_ | ' | '| | ' \/ _` | \ \ \ \ \/ )| |)| | | | | || (| | ) ) ) ) ' |_| .|| ||| |_, | / / / / =========|_|==============|/=//// :: Spring Boot :: (v3.0.1)
2023-01-19T11:49:43.742+08:00 INFO 87661 --- [ main] c.e.c.CloudConfigServerApplication : Starting CloudConfigServerApplication using Java 17.0.5 with PID 87661 (/Users/user/Downloads/cloud-config-server/target/classes started by user in /Users/user/Downloads/cloud-config-server) 2023-01-19T11:49:43.746+08:00 INFO 87661 --- [ main] c.e.c.CloudConfigServerApplication : No active profile set, falling back to 1 default profile: "default" 2023-01-19T11:49:45.855+08:00 INFO 87661 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=1e57de0b-ce4d-3b56-b065-26410dbe8188 [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 21.064 s [INFO] Finished at: 2023-01-19T11:49:50+08:00 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:3.0.1:process-aot (process-aot) on project cloud-config-server: Unable to compile generated source [ERROR] org.springframework.cloud.config.server.bootstrap.ConfigServerBootstrapOverridesAutoConfiguration.ConfigServerBootstrapOverridesLifecycle 在 org.springframework.cloud.config.server.bootstra.ConfigServerBootstrapOverridesAutoConfiguration 中是 private 访问控制 /Users/user/Downloads/cloud-config-server/target/spring-aot/main/sources/org/springframework/cloud/config/server/bootstrap/CorverBootstrapOverridesAutoConfiguration__BeanDefinitions.java 26:86 [ERROR] org.springframework.cloud.config.server.bootstrap.ConfigServerBootstrapOverridesAutoConfiguration.ConfigServerBootstrapOverridesLifecycle 在 org.springframework.cloud.config.server.bootstra.ConfigServerBootstrapOverridesAutoConfiguration 中是 private 访问控制 /Users/user/Downloads/cloud-config-server/target/spring-aot/main/sources/org/springframework/cloud/config/server/bootstrap/CorverBootstrapOverridesAutoConfiguration__BeanDefinitions.java 28:81 [ERROR] org.springframework.cloud.config.server.bootstrap.ConfigServerBootstrapOverridesAutoConfiguration.ConfigServerBootstrapOverridesLifecycle 在 org.springframework.cloud.config.server.bootstra.ConfigServerBootstrapOverridesAutoConfiguration 中是 private 访问控制 /Users/user/Downloads/cloud-config-server/target/spring-aot/main/sources/org/springframework/cloud/config/server/bootstrap/CorverBootstrapOverridesAutoConfiguration__BeanDefinitions.java 35:72 [ERROR] -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
Comment From: ryanjbaxter
@OlgaMaciaszek did you do some testing compiling the config server natively with spring.cloud.config.server.bootstrap=true
? Seems like it could be a class access issue? https://github.com/spring-cloud/spring-cloud-config/pull/2212
Comment From: OlgaMaciaszek
@ryanjbaxter We've always considered Bootstrap mode out of scope for native - it's also marked so in the docs.
Comment From: ryanjbaxter
Oh right, i forgot about the blocking issue.
https://docs.spring.io/spring-cloud-config/docs/current/reference/html/#_aot_and_native_image_support