{"record":{"id":"7bf396fc5208f3d7","repo":"quarkusio/quarkus","slug":"multiple-factory-beans-with-type-type-getname","errorCode":null,"errorMessage":"multiple factory beans with type + type.getName() + found for keystore type '\" + typeName + \"'","messagePattern":"multiple factory beans with type \\+ type\\.getName\\(\\) \\+ found for keystore type '\" \\+ typeName \\+ \"'","errorType":"exception","errorClass":"AmbiguousResolutionException","httpStatus":null,"severity":"error","filePath":"extensions/tls-registry/runtime/src/main/java/io/quarkus/tls/runtime/CertificateRecorder.java","lineNumber":269,"sourceCode":"                    \"multiple beans with type \" + type.getName() + \" found for TLS configuration \" + bucketName);\n        }\n        if (instances.isEmpty()) {\n            return new InstanceHandle<T>() {\n                @Override\n                public T get() {\n                    return null;\n                }\n            };\n        }\n        return instances.get(0);\n    }\n\n    static <T> InstanceHandle<T> lookupFactory(Class<T> type, String typeName) {\n        var container = Arc.container();\n        var qualifier = Identifier.Literal.of(typeName);\n        var instances = container.listAll(type, qualifier);\n        if (instances.size() > 1) {\n            throw new AmbiguousResolutionException(\n                    \"multiple factory beans with type \" + type.getName() + \" found for keystore type '\" + typeName + \"'\");\n        }\n        if (instances.isEmpty()) {\n            return new InstanceHandle<T>() {\n                @Override\n                public T get() {\n                    return null;\n                }\n            };\n        }\n        return instances.get(0);\n    }\n}\n","sourceCodeStart":251,"sourceCodeEnd":283,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/tls-registry/runtime/src/main/java/io/quarkus/tls/runtime/CertificateRecorder.java#L251-L283","documentation":"Keystore types (PEM, PKCS12, JKS, other) are backed by factory beans looked up via an @Identifier qualifier named after the type string. lookupFactory throws AmbiguousResolutionException when two beans of the requested factory type carry the same identifier, because Arc cannot determine which factory should build the keystore.","triggerScenarios":" getKeyStore/getTrustStore resolving a keystore factory by typeName when two beans of that factory type are annotated with the same @Identifier(typeName).","commonSituations":"Shipping a custom factory for a keystore type (e.g. a custom PKCS12 factory) alongside Quarkus's built-in factory with the same @Identifier; including two extensions/libraries that each register a factory for the same type name; misconfigured @Identifier values (copy-paste leaving two beans with identical identifiers).","solutions":["Remove or de-duplicate one of the conflicting factory beans so exactly one factory exists per keystore type name.","Rename your custom factory's @Identifier (or use a distinct keystore type via 'other') so it no longer collides with the built-in factory.","If the collision comes from a dependency, exclude its factory bean (e.g. do not bring in the library, or use an exclusion) so only your factory remains."],"exampleFix":"// before\n@ApplicationScoped\n@Identifier(\"pkcs12\")\nclass MyP12Factory implements KeyStoreFactory { ... }\n// after\n@ApplicationScoped\n@Identifier(\"my-custom-pkcs12\")\nclass MyP12Factory implements KeyStoreFactory { ... }\n// and reference it via keystore config 'type' or the 'other' provider mechanism","handlingStrategy":"validation","validationCode":"List<InstanceHandle<KeyStoreFactory>> factories = Arc.container()\n    .listAll(KeyStoreFactory.class, Identifier.Literal.of(\"pkcs12\"));\nif (factories.size() > 1) {\n    throw new IllegalStateException(\"More than one factory registered for keystore type 'pkcs12'\");\n}","typeGuard":"boolean hasUniqueFactory(Class<?> factoryType, String typeName) {\n    return Arc.container().listAll(factoryType, Identifier.Literal.of(typeName)).size() == 1;\n}","tryCatchPattern":"try {\n    KeyStore ks = tlsConfig.getKeyStore();\n} catch (AmbiguousResolutionException e) {\n    log.error(\"Duplicate keystore factory beans; inspect @Identifier on factory classes\", e);\n}","preventionTips":["Keep one factory bean per keystore type name; place custom implementations under a distinct @Identifier or the 'other' mechanism.","Audit third-party TLS extensions for factories that collide with built-in PEM/PKCS12/JKS identifiers.","Keep @Identifier strings consistent with keystore config 'type' values."],"tags":["cdi","quarkus","ambiguous-bean","keystore"],"backgroundTag":"ambiguous-cdi-bean","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}