简体   繁体   English

如何从Eclipse中的Java类跳转到Spring上下文XML文件

[英]How to jump to Spring context XML file from Java Class in Eclipse

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. 我很好地阅读了如何从Eclipse的Java类中查找Spring XML定义的问题但是它似乎并没有回答我的类似问题。

I would like to jump from Java class in editor to the spring context xml file. 我想从编辑器中的Java类跳转到spring上下文xml文件。

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=... >". 如果我在编辑器中突出显示了一个类声明,请通过按快捷键或单击某个图标,它应打开具有bean初始化定义的相应spring上下文xml,并跳转到初始化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... >" 如果我在编辑器中突出显示set方法,它将执行类似的操作,但是会跳转到该属性设置为“ <property name = method_name ...>”的位置

I am using Eclipse Java EE IDE for Web Developers Indigo SR2. 我正在为Web开发人员Indigo SR2使用Eclipse Java EE IDE。 I have installed Spring IDE Developers and SpringSource. 我已经安装了Spring IDE Developers和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. 我已将Spring性质添加到项目中,将上下文xml添加到了项目属性Spring Beans支持配置文件中,并且可以在上下文文件和Java类的文件图标装饰器上看到“ S”,但是我找不到跳转的方法从Java类到spring上下文xml。

My colleague is using IntelliJ and they could see a bean icon in their editor next to class declaration. 我的同事正在使用IntelliJ,他们可以在编辑器中的类声明旁边看到一个Bean图标。 I would hope to see something similar on Eclipse. 我希望在Eclipse上看到类似的东西。 Ideally, not only class level, but also next to set methods. 理想情况下,不仅是类级别,而且要紧接set方法。

Any advice will be much appreciated! 任何建议将不胜感激!

Thanks Gerry 谢谢格里

The desired action is provided by the Spring Tools (Spring Tool Suite), which can be installed the usual way, ie as Feature, or via the Eclipse Marketplace. 所需的操作由Spring Tools(Spring Tool Suite)提供,可以按通常的方式安装,即作为Feature或通过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. 并且,在项目配置project> properties的“ Spring”选项卡中,您需要定义所有Spring XML文件。

In Eclipse Mars, all of this will be setup automatically, when importing a Maven project and using the M2E plugin. 在Eclipse Mars中,当导入Maven项目并使用M2E插件时,所有这些都将自动设置。 Moreover, there is also a setting in the "Spring" tab, which allows to autodetect your Spring XML files. 此外,“ Spring”选项卡中还有一个设置,可以自动检测您的Spring XML文件。 Anyhow, the spring project configuration needs to parse and evaluate those XML files during the incremental build of your project. 无论如何,spring项目配置需要在项目的增量构建期间解析和评估那些XML文件。 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" 按名称调用它:按ctl-3并开始输入名称“ open spring bean”
  • set up a custom key binding: press ctrl-shift-L and ctrl-shift-L again, to get the keybindings editor. 设置自定义键绑定:再次按ctrl-shift-L和ctrl-shift-L,以获取键绑定编辑器。 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 (ey I used ctrl-y, which is good to type with the left hand while using the mouse with the right hand). 使用搜索找到功能“ open spring bean”,确保选择“ in windows”作为范围并添加所需的键绑定(我使用了ctrl-y,使用时最好用左手键入用右手的鼠标)。

This function will give you a Eclipse typical quick-hover-and-search box, where you can start typing. 此功能将为您提供一个Eclipse典型的快速悬停和搜索框,您可以在其中开始键入。 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. 如果光标位于bean实现Java类的类名称上,则该视图将已被填充,您只需按Enter键。


<Rant> This is such a crucial and basic feature. <Rant> 这是一个至关重要的基本功能。 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. 为什么Spring和Eclipse的人无法以易于发现的方式来设置和记录基础知识,这超出了我的范围。 No wonder every idiot thinks that IntelliJ is vastly superior, which it is not. 难怪每个白痴都认为IntelliJ优越得多,事实并非如此。 In reality, both are on equal footing and have their strengths and weaknesses here and there. 实际上,两者都处于平等地位,并且在各处都有其优点和缺点。 </Rant>

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). 我不知道SpringSource或此类资源是否具有任何特定的键,但是可以使用旧的Ctrl-shift-R(导航->打开资源)来搜索和打开工作区中的非Java文件(例如.xmls)。和.properties),对于类,您可以使用Ctrl-shift-T(导航->打开类型)。 When the search window opens, just start typing file- or class name (you can also use wildcards like * and ?). 当搜索窗口打开时,只需开始输入文件名或类名(您也可以使用通配符,例如*和?)。

如果您使用的是Spring Tools Suite,请使用Alt+Shift+B

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 How to find Spring XML definition from Java Class in Eclipse - How to find Spring XML definition from Java Class in Eclipse eclipse的Spring上下文XML验证器? - Spring context XML validator for eclipse? 使用eclipse / sts编辑spring xml源 - 缺少“mark occurrences”和“跳转到另一个文件中的bean”? - editing spring xml source with eclipse/sts - missing “mark occurrences” and “jump to bean in another file”? Eclipse控制台超链接只能跳到引用库中的Java类文件 - Eclipse console hyperlink only can jump to Java class file in referenced libraries 如何将参数传递给eclipse插件中的context.xml文件? - How to Pass parameters to context.xml file in eclipse plugin? 如何跳转到Eclipse中的XML资源而不是R.java - How do I jump to XML resources in Eclipse instead of R.java 如何从不受保护的上下文中加载由 jar2exe 加密或保护的 class 文件,例如 Eclipse Birt? - How to load a class file encrypted or protected by jar2exe from unprotected context, for example, Eclipse Birt? 如何在Eclipse中打开文件并跳转到特定行? - How to open a file in Eclipse AND jump to a specific line? 如何从资源引用xml文件? 日食 - How to reference an xml file from resources? Eclipse eclipse中从方法定义跳转到方法调用【Java透视】 - Jump to method call from method definition in eclipse [Java perspective]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM