2

I well read the question How to find Spring XML definition from Java Class in Eclipse but it does not seem to answer similar question from me.

I would like to jump from Java class in editor to the spring context xml file.

If I highlighted a class declaration in editor, by pressing a shortcut key or clicking on some icon, it should open the corresponding spring context xml which have the bean initialization definition and jump to the line which initializes the bean "< bean id=... >". If I highlighted a set method in editor, it will do something similar but jump to where the property is set "< property name=method_name... >"

I am using Eclipse Java EE IDE for Web Developers Indigo SR2. I have installed Spring IDE Developers and SpringSource. I have added Spring nature to the project, added context xml to the project property Spring Beans Support Config Files, and could see the "S" on file icon decorator of the context file and java class, but I could NOT find a way to jump from the Java class to the spring context xml.

My colleague is using IntelliJ and they could see a bean icon in their editor next to class declaration. I would hope to see something similar on Eclipse. Ideally, not only class level, but also next to set methods.

Any advice will be much appreciated!

Thanks Gerry

Community
  • 1
  • 1
Gerry
  • 127
  • 2
  • 12

3 Answers3

2

The desired action is provided by the Spring Tools (Spring Tool Suite), which can be installed the usual way, i.e. as Feature, or via the Eclipse Marketplace.

  • your current project needs the "spring project nature"
  • moreover, your build must include the "spring project builder"
  • and, in your project configuration project>properties, "Spring" tab, you need to define all your Spring XML files.

In Eclipse Mars, all of this will be setup automatically, when importing a Maven project and using the M2E plugin. Moreover, there is also a setting in the "Spring" tab, which allows to autodetect your Spring XML files. Anyhow, the spring project configuration needs to parse and evaluate those XML files during the incremental build of your project. So far for the prerequisites.

The actual function is called "open spring bean"

By default, there is no keybinding for this operation, so either

  • invoke it by name: press ctl-3 and start typing the name "open spring bean"
  • set up a custom key binding: press ctrl-shift-L and ctrl-shift-L again, to get the keybindings editor. Use the search to get to the function "open spring bean", make sure you select "in windows" as scope and add the key binding you like (e.y. I used ctrl-y, which is good to type with the left hand while using the mouse with the right hand).

This function will give you a Eclipse typical quick-hover-and-search box, where you can start typing. If the cursor is on the class name of the bean implementation Java class, the view will be populated already and you just need to hit enter.


<Rant> This is such a crucial and basic feature. Why the Spring and Eclipse folks are incapable to set up and document the very basics in a way easy to discover is beyond me. No wonder every idiot thinks that IntelliJ is vastly superior, which it is not. In reality, both are on equal footing and have their strengths and weaknesses here and there. </Rant>

Ichthyo
  • 7,290
  • 2
  • 22
  • 29
  • 1
    Hi Ichthyo, sorry to come back so late and I have missed your answer for such a long time. Thanks for the information and it works! Let me "rant" with you. Eclipse could be greater if they work closer together by giving us the little bean icon next to the class/method declaration! – Gerry Mar 28 '16 at 05:32
0

I don't know if SpringSource or such have any specific keys for these, but good old Ctrl-shift-R (Navigate -> Open Resource) can be used to search for and open non-Java files in the workspace (like .xmls and .properties), for classes you can use Ctrl-shift-T (Navigate -> Open Type). When the search window opens, just start typing file- or class name (you can also use wildcards like * and ?).

esaj
  • 15,369
  • 4
  • 35
  • 52
  • Hi esaj, basically I would like to do this. If I highlighted a class declaration in editor, by pressing a shortcut key or clicking on some icon, it could open the corresponding spring context xml which have the bean initialization definition and jump to the line which initializes the bean "". If I highlighted a set method in editor, it will do something similar but jump to where the property is set "". – Gerry May 23 '12 at 09:01
  • @Gerry: unfortunately, I haven't worked with the Spring Source Tool Suite, so I don't know if it has such functionality. – esaj May 24 '12 at 05:54
0

Use Alt+Shift+B if you are using Spring Tools Suite.

Sai A
  • 101
  • 1
  • 2
  • 10