Eclipse:spring bean和context的open声明/资源 [英] Eclipse: open declaration/resource for spring beans and contexts

查看:185
本文介绍了Eclipse:spring bean和context的open声明/资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在看我的同事在IntelliJ中工作时,我很羡慕地注意到他可以Ctrl / Command +点击Java注释或Spring上下文文件和IntelliJ中的spring bean,context或resource的名字将打开支持声明或文件。



我已经安装了用于Eclipse的STS套件插件,但这只能让我有能力打开bean的声明在一个spring context文件中。例如,命令+单击仅在我的上下文文件中工作:< bean ... ref =bean-name/>



具体来说,无法自动打开声明/资源的东西是:




  • 在我的上下文文件:< import resource =classpath:config / anotherContext.xml/> ,我无法打开资源anotherContext.xml。开放的资源对话有助于,但不告诉我我的类路径实际上给了我哪一个。

  • 在我的Java文件中: @ContextConfiguration({classpath: / / code>,我无法自动打开hasAnotherContext.xml的资源。

  • 在我的Java文件中: @Resource(name =another-bean-name),我无法打开bean声明。这个在Eclipse中特别难以发现,我还没有找到一个简单的方法来发现缺少完整搜索的bean声明。



当然,Eclipse中有一种方法可以自动发现弹簧bean和上下文的声明或资源,因为它们用于Java注释和上下文文件中。

解决方案

我为我的第一个例子找到了一个解决方案,具体来说,在这个StackOverflow问题。具体来说,在Spring-> Beans Support下的项目属性中,选中复选框,启用< import />元素在配置文件中



这也可以为导入的spring资源文件中定义的bean打开bean声明。



我还没有发现类似的功能,用于通过注释连接Spring资源和bean的Java文件。


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?

解决方案

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.

这篇关于Eclipse:spring bean和context的open声明/资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆