Intellij: Go to autowired bean definition

2020-07-06 06:23发布

问题:

I looking for quick way to find bean definition by their @Autowired dependency in java code. Suppose I have:

@Autowired 
private JdbcTemplate template;

I want IDEA tell me in which xml file is the definition of template bean. How to do that?

回答1:

If you have the spring plugin installed and active you should see some icons on the left gutter which help you to identify the place where the bean has been defined, either xml or annotation. If you have multiple spring profiles you may have to chose the active one.



回答2:

First install spring plugin by Ctrl+Alt+S under IDE Settings, select Plugins. In the right-hand part of the dialog, on the Plugins page, type spring in the search box. If the check box to the left of Spring Support is not selected, select it. If you are going to use particular Spring frameworks (Spring Security, Spring Integration, etc.), make sure that the check boxes next to their names are also selected.

Then the icons on the left(near the code line-number) helps to identify the bean definition