使用Spring Native构建GCP Cloud Run应用失败求助
问题:Spring Native构建Spring Boot应用至GCP Cloud Run时的编译参数错误
问题场景
尝试使用Spring Native构建Spring Boot 3.0.6(Java 17、Gradle 7.5)应用的原生版本,部署目标为GCP Cloud Run。执行Gradle任务bootBuildImage时出现以下错误:
Exception in thread "main" org.springframework.boot.context.properties.bind.MissingParametersCompilerArgumentException: Constructor binding in a native image requires compilation with -parameters but the following classes were compiled without it: com.google.cloud.spring.core.Credentials at org.springframework.boot.context.properties.bind.BindableRuntimeHintsRegistrar.registerHints(BindableRuntimeHintsRegistrar.java:91) at org.springframework.boot.context.properties.ConfigurationPropertiesBeanFactoryInitializationAotProcessor$ConfigurationPropertiesReflectionHintsContribution.applyTo(ConfigurationPropertiesBeanFactoryInitializationAotProcessor.java:70) at org.springframework.context.aot.BeanFactoryInitializationAotContributions.applyTo(BeanFactoryInitializationAotContributions.java:78) at org.springframework.context.aot.ApplicationContextAotGenerator.lambda$processAheadOfTime$0(ApplicationContextAotGenerator.java:58) at org.springframework.context.aot.ApplicationContextAotGenerator.withCglibClassHandler(ApplicationContextAotGenerator.java:67) at org.springframework.context.aot.ApplicationContextAotGenerator.processAheadOfTime(ApplicationContextAotGenerator.java:53) at org.springframework.context.aot.ContextAotProcessor.performAotProcessing(ContextAotProcessor.java:106) at org.springframework.context.aot.ContextAotProcessor.doProcess(ContextAotProcessor.java:84) at org.springframework.context.aot.ContextAotProcessor.doProcess(ContextAotProcessor.java:49) at org.springframework.context.aot.AbstractAotProcessor.process(AbstractAotProcessor.java:82) at org.springframework.boot.SpringApplicationAotProcessor.main(SpringApplicationAotProcessor.java:80)
疑问与排查方向
我认为Spring Native构建流程默认已包含-parameters编译参数,这个判断是否正确?如果正确,问题应该是com.google.cloud.spring.core.Credentials类未使用该参数编译导致的。
可复现的build.gradle配置
plugins { id 'java' id 'org.springframework.boot' version '3.0.6' id 'io.spring.dependency-management' version '1.1.0' id 'org.graalvm.buildtools.native' version '0.9.20' } group = 'com.example' version = '0.0.1-SNAPSHOT' sourceCompatibility = '17' configurations { compileOnly { extendsFrom annotationProcessor } } repositories { mavenCentral() } ext { set('springCloudGcpVersion', "4.1.4") set('springCloudVersion', "2022.0.2") } dependencies { implementation 'org.springframework.boot:spring-boot-starter-validation' implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-webflux' implementation 'com.google.cloud:spring-cloud-gcp-starter' implementation 'com.google.cloud:spring-cloud-gcp-starter-storage' compileOnly 'org.projectlombok:lombok' developmentOnly 'org.springframework.boot:spring-boot-devtools' annotationProcessor 'org.projectlombok:lombok' testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'io.projectreactor:reactor-test' } dependencyManagement { imports { mavenBom "com.google.cloud:spring-cloud-gcp-dependencies:${springCloudGcpVersion}" mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}" } } tasks.named('test') { useJUnitPlatform() }
更新说明
经进一步排查,发现GCP相关库目前暂不支持Spring Native,该问题在官方代码仓库已有对应的议题记录。
内容的提问来源于stack exchange,提问作者Ben
相关产品推荐
相关产品推荐

