2

While watching one of my colleagues work in IntelliJ, I was jealous to note that he could Ctrl/Command+Click on the name of a spring bean, context, or resource in either a Java annotation or a Spring context file and IntelliJ would open the backing declaration or file.

I've installed the STS suite of plugins for Eclipse, but this has only given me the ability to open declarations for beans referred to in a spring context file. E.g., command+click only works in my context file for: <bean ... ref="bean-name"/>.

Specifically, things I can't open the declaration/resource for automatically are:

  • In my context file: <import resource="classpath:config/anotherContext.xml"/>, I cannot open the resource anotherContext.xml. The open resource dialogue helps, but doesn't tell me which one my classpath is actually giving me.
  • In my Java file: @ContextConfiguration({"classpath:/config/yetAnotherContext.xml"}), I cannot automatically open the resource of yetAnotherContext.xml.
  • In my Java file: @Resource(name = "another-bean-name"), I cannot open the bean declaration. This one is especially difficult to discover in Eclipse, I haven't figured out an easy way to discover the bean declaration short of full search.

Surely there's a way in Eclipse to automatically discover declarations or resources for spring beans and contexts as they are used in both Java annotations and context files?

Malina Kirn
  • 2,073
  • 1
  • 21
  • 19
  • If you install STS on eclipse you can view *Spring Explorer* window on Spring perspective and see list of xml configuration files and beans inside it. This won't give you direct referral from the annotations but still help a little – gerrytan Jul 02 '14 at 23:01
  • Thanks, the list of beans is indeed helpful. It makes my third example above easier to deal with, though only for beans defined in my context files. Still can't seem to find beans defined outside my project, but in my classpath. – Malina Kirn Jul 07 '14 at 18:10

1 Answers1

1

I found a solution for my first example, specifically, finding a spring resource imported into a spring context file in this StackOverflow question. Specifically, in the project properties under Spring->Beans Support, select the checkbox for Enable support for <import /> element in configuration files.

This also gives the ability to open bean declarations for beans defined in imported spring resource files.

I have yet to discover similar functionality for Java files that wire in Spring resources and beans via annotations.

Community
  • 1
  • 1
Malina Kirn
  • 2,073
  • 1
  • 21
  • 19