Spring custom annotation is not recognized as @Autowired analogue
已回答
Hello,
Could someone describe me how to configure Idea to recognize custom Spring annotations?
I'm using Spring and java-configs, Spring facet is added to my modules, so each bean annotated by @Autowire and declared in @Configuration class is shown correctly. But we have custom annotation like
@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Bean
@Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
public @interface CustomController {
}
and beans that are annotated by it are not recognized by Idea:
- methods in @Configuration file is marked as never used
- injection in another class is marked as invalid with message "Could not autowire. No beans of '...' type found."
@Configuration
public class MasterdataRequestConfiguration {
@CustomController
MasterdataRequestController masterdataRequestController() {
return new MasterdataRequestController();
}
@Bean
TerminalAttributesService terminalAttributesService() {
return new TerminalAttributesService();
}
terminalAttributesService is injected without warnings but masterdataRequestController is not found by Idea with such configuration's file.
Is there any way to point that this annotation is a @Bean too?
Please note that I don't want to disable this check - it can be very useful.
请先登录再写评论。
What version of IntelliJ IDEA do you use?
I'm using version 15.0.2.
Do you mean that such annotations are recognized somewhere? :)
Sorry, indeed meta-annotations for "@Bean" are not supported currently. Please watch https://youtrack.jetbrains.com/issue/IDEA-149463 for progress. Thanks for reporting!
So, any update for this question. I met a similar scenario.
When I use `@SpringBootTest`, all the `@Autowired` can be recognized.
However, when I use custom annotation which contains `@SprintBootTest`, it doesn't work.
Got an inspection. `Autowired members must be defined in the valid spring bean`.
Hi Kimi Chen Could you prepare and provide a small project sample? The files can be uploaded at https://uploads.jetbrains.com (do not forget to specify the UploadID)