spring-projects/spring-ai · warning
error when registering Bedrock types
Error message
error when registering Bedrock types
What it means
BedrockRuntimeHints.registerHints() registers reflection/serialization/resource hints for GraalVM native image. Any Throwable during registration is only logged at WARN ('error when registering Bedrock types') — not thrown. The risk is silent native-image runtime failures (missing reflection metadata) rather than an immediate crash.
Solutions
- Read the logged stack trace following the WARN line to identify which registration step and class failed.
- Align the AWS Bedrock SDK version with the one expected by your spring-ai-bedrock release.
- Manually add @RegisterReflectionForBinding / runtime hints for the missing classes in your own RuntimeHintsRegistrar as a workaround.
- Test the native image early; if the WARN appears but inference works, no action is needed.
Defensive patterns
Strategy: fallback
Try / catch
// not thrown; watch build logs: if 'error when registering Bedrock types' appears, add manual hints
static class FallbackHints implements RuntimeHintsRegistrar { public void registerHints(RuntimeHints h, ClassLoader cl) { h.reflection().registerType(BedrockAiApi.class, MemberCategory.values()); } } Prevention
- Run a native-image smoke test invoking a Bedrock call early in CI
- Keep spring-ai-bedrock and AWS SDK versions aligned
- Read the WARN stack trace to find which hint registration failed instead of guessing
When it happens
Trigger: Building a GraalVM native image (or running AOT processing) with the Bedrock model on the classpath when registerBedrockRuntimeService/registerSerializationClasses/registerResources throws — e.g. a class listed for reflection cannot be loaded, or a TypeReference points to a class absent in this Bedrock SDK version.
Common situations: Version drift between spring-ai-bedrock and the AWS SDK (class names moved/removed); shaded/relocated AWS SDK jars; native-image builds with a stripped dependency set.
Related errors
- ClassNotFoundException (wrapped RuntimeException)
- Chat completion is not supported for this model:
- Connection to blocked internal address rejected for host ''
- Documents are ingested via data source sync, not direct add.
- Documents are managed via data source, not direct delete.
AI-assisted analysis of spring-projects/spring-ai@98a7beda4f (2026-09-11).
Data as JSON: /api/errors/0c5247a775b97225.
Report an issue: GitHub.
Appendix: source
Thrown at models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/aot/BedrockRuntimeHints.java:71
private final Log log = LogFactory.getLog(BedrockRuntimeHints.class);
private final MemberCategory[] memberCategories = MemberCategory.values();
private final Collection<TypeReference> allClasses;
BedrockRuntimeHints() {
this.allClasses = this.find(this.rootPackage);
}
@Override
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
try {
this.registerBedrockRuntimeService(hints);
this.registerSerializationClasses(hints);
this.registerResources(hints);
} //
catch (Throwable ex) {
this.log.warn("error when registering Bedrock types", ex);
}
}
private void registerBedrockRuntimeService(RuntimeHints hints) {
var pkg = this.rootPackage + ".services.bedrockruntime";
var all = new HashSet<TypeReference>();
for (var clzz : this.allClasses) {
if (clzz.getName().contains("Bedrock") && clzz.getName().contains("Client")) {
all.add(clzz);
}
}
var modelPkg = pkg + ".model";
all.addAll(this.find(modelPkg));
all.forEach(tr -> hints.reflection().registerType(tr, this.memberCategories));
}
private void registerSerializationClasses(RuntimeHints hints) {
for (var c : this.allClasses) {View on GitHub (pinned to 98a7beda4f)