在支持 Spring 的 IDE 中是否容易找到类/方法引用

发布于 2024-12-18 07:42:23 字数 224 浏览 6 评论 0原文

我在 Eclipse 方面拥有多年的 Java 经验,现在想尝试一下 Spring。在阅读了一些教程后,我有这样一个问题:在任何支持 Spring 的 IDE 中找到类/方法引用是否很容易(甚至可能)?通过使用 Spring,某些类之间不应该直接引用,而是在 xml 文件中配置它们。

更进一步:如果我的项目变大,比如有数千或数百个类,如何管理这些 xml 文件?我的意思是,也许很容易在那些复杂的配置文件中迷失方向。

I have years of Java experience on Eclipse and now would like to get my feet wet with Spring. After read some tutorials I have such a question: is it easy (or even possible) to find classes/methods references in any IDE that supports Spring? By using Spring there should be no direct references among some classes, instead they are configured in xml files.

Even further: how to manage those xml files if my project gets large, say with thousands or hundreds classes? I mean perhaps it is easy to get lost among those complicated configuration files.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

掀纱窥君容 2024-12-25 07:42:23

Spring 是一个依赖注入引擎。这意味着它将A的实例注入到依赖于A的bean中。因此,如果bean B依赖于A,它将有一个类型为A的字段,Spring将为您初始化该字段。

因此,查找引用非常简单:选择 A 的方法之一,选择“调用层次结构”,如果 B 调用 A 的该方法,Eclipse 就会找到它。它与任何其他不使用 Spring 的 Java 项目没有什么不同。

关于XML文件的大小,Spring还使用注解来注入bean,因此XML文件可以减少到最小。

Spring is a dependency injection engine. This means that it injects instances of A into beans which are dependent on A. So if bean B has a dependency on A, it will have a field of type A, and Spring will initialize this field for you.

Finding the references is thus trivial: select one of A's methods, choose "Call hierarchy", and if B calls this method of A, Eclipse will find it. It's not different from any other Java project not using Spring.

Regarding the size of the XML files, Spring also uses annotations to inject beans, so the XML file can be reduced to a minimum.

骷髅 2024-12-25 07:42:23

使用STS或者Spring-IDE插件,可以在spring中点击类定义xml 文件,您将被直接“转发”到班级。

例如,您构建一个视图,其中 bean 实例显示在类似 uml 的类图中。了解哪个 bean 如何与其他 bean 连接一次。

但实际上您并不需要它。
如果您针对接口实现,那么哪个具体类实现该接口并不重要。
如果您针对一个类实现,那么您已经知道该类了。

With STS or the Spring-IDE plugin, it is possible to click on the class definition in the spring xml file and you will be direcly "forwarded" to the class.

And for example you build a view where the bean instances are displayed in an uml like class diagram. To get an overview how which bean is connected to other once.

But really you will not need that.
If you implement against an interface then it should not matter which concrete class is implementing the interface.
And if you implement against an class, then you know that class already.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文