{"record":{"id":"6386cd7e017db8d6","repo":"quarkusio/quarkus","slug":"annotationinstance-annotationinstance-is-an-inva","errorCode":null,"errorMessage":"AnnotationInstance <annotationInstance> is an invalid target. Only Method targets are supported","messagePattern":"AnnotationInstance <annotationInstance> is an invalid target\\. Only Method targets are supported","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"extensions/spring-di/deployment/src/main/java/io/quarkus/spring/di/deployment/SpringDIProcessor.java","lineNumber":518,"sourceCode":"    private String getBeanNameFromStereotypeInstance(AnnotationInstance annotationInstance) {\n        if (annotationInstance.target().kind() != AnnotationTarget.Kind.CLASS) {\n            throw new IllegalStateException(\n                    \"AnnotationInstance \" + annotationInstance + \" is an invalid target. Only Class targets are supported\");\n        }\n        final AnnotationValue value = annotationInstance.value();\n        if ((value == null) || value.asString().isEmpty()) {\n            return getDefaultBeanNameFromClass(annotationInstance.target().asClass().name().toString());\n        } else {\n            return value.asString();\n        }\n    }\n\n    /**\n     * Meant to be called with instances of @Bean\n     */\n    private String getBeanNameFromBeanInstance(AnnotationInstance annotationInstance) {\n        if (annotationInstance.target().kind() != AnnotationTarget.Kind.METHOD) {\n            throw new IllegalStateException(\n                    \"AnnotationInstance \" + annotationInstance + \" is an invalid target. Only Method targets are supported\");\n        }\n\n        String beanName = null;\n        final AnnotationValue beanNameAnnotationValue = annotationInstance.value(\"name\");\n        if (beanNameAnnotationValue != null) {\n            beanName = determineName(beanNameAnnotationValue);\n        }\n        if (beanName == null || beanName.isEmpty()) {\n            final AnnotationValue beanValueAnnotationValue = annotationInstance.value();\n            if (beanValueAnnotationValue != null) {\n                beanName = determineName(beanValueAnnotationValue);\n            }\n        }\n        if (beanName == null || beanName.isEmpty()) {\n            beanName = annotationInstance.target().asMethod().name();\n        }\n","sourceCodeStart":500,"sourceCodeEnd":536,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/spring-di/deployment/src/main/java/io/quarkus/spring/di/deployment/SpringDIProcessor.java#L500-L536","documentation":"The Spring DI extension derives bean names from @Bean methods in configuration classes. This method expects the @Bean annotation instance to target a method; when the target is not a method, the build fails with this IllegalStateException. @Bean is only meaningful on methods producing beans.","triggerScenarios":"@Bean found on a non-method target (class, field, parameter) — typically via misuse, a typo, or a meta-annotation that drags @Bean onto a class/field during index scanning.","commonSituations":"Copy-paste of @Bean onto a configuration class; applying @Bean to fields intending field injection; custom annotations annotated with @Bean; migration tooling misplacing annotations.","solutions":["Move @Bean to a public method inside a @Configuration class that returns the bean","Remove @Bean from classes/fields; annotate those with @Component or inject via constructor","If a custom annotation composes @Bean, restrict it to @Target(METHOD)","Re-index and confirm no stray @Bean annotation instances exist on non-method targets"],"exampleFix":"// before\n@Bean\npublic class MyConfig { }\n\n// after\n@Configuration\npublic class MyConfig {\n    @Bean\n    public MyService myService() { return new MyService(); }\n}","handlingStrategy":"validation","validationCode":"// Place @Bean only on methods:\n@Configuration\npublic class MyConfig {\n    @Bean // method target only\n    public MyService myService() { return new MyService(); }\n}\n// Composed annotations: @Target(ElementType.METHOD)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Annotate @Bean only on @Configuration class methods","Never put @Bean on classes or fields","Constrain composed annotations with @Target(ElementType.METHOD)","Review annotation placement after using migration tooling"],"tags":["quarkus","spring-di","annotations","build-time","cdi"],"backgroundTag":"invalid-annotation-target","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}