如何重构使用 spring 自动装配的代码库
我继承了两个相当重要的代码库,它们使用 spring 来配置应用程序。现在我需要重新配置应用程序。但许多配置是通过自动装配提供的,因此几乎不可能找出实际配置是什么。
这些项目规模适中,每个项目大约有 20 个左右的 Maven 模块,包括集成测试模块等。大多数模块出于各种目的定义了一些应用程序上下文,其中包含一两个本地 spring 配置文件以及它所依赖的核心模块中的一两个。结果是无数的配置,并且我无法在不冒破坏某些上游或下游模块中的依赖关系的风险的情况下更改类或变量名称(或 setter 方法),即使在项目中的任何地方都看不到此类依赖关系。
如何在 Spring 中有效地使用自动装配依赖项?
任何人,也许是真正喜欢自动装配的人,都可以提供一些关于如何有效地使用它们的见解吗?
(我还继承了一个小项目,它结合了 xml 文件、自动装配和注释驱动的配置,使依赖关系完全难以处理,但我稍后会将这些注释保存为一个单独的问题)
I've inherited two fairly non-trivial codebases that uses spring for configuring the applications. Now I need to reconfigure the applications. But lots of the configuration is provided through autowiring so it is almost impossible to find out what the actual configuration is.
The projects are moderately sized, some 20-ish maven modules per project including integration test modules and such. Most modules define a few application contexts for various purposes, that contain one or two local spring config files along with one or two from the core modules it depends on. The result is a myriad of configurations, and that I cannot alter a class or variable name (or setter method) without risking breaking dependencies in some upstream or downstream module, even if no such dependency is visible anywhere in the project.
How do I work effectively with autowired dependencies in spring?
Can anyone, perhaps someone who actually likes autowiring, provide some insight into how you work with them effectively?
(I also inherited a small project that combines xml-files, autowiring and annotation-driven config, making dependency relations completely intractable, but I'll save those annotations for a separate question later)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 Intellij (我有版本 9 Ultimate)执行自动连接 bean 的重构。 Intellij 还可以选择显式地显示自动装配依赖关系。下面提供的链接
http://blogs.jetbrains.com /idea/2009/03/making-spring-autowired-dependencies-explicit/
You can perform re-factoring of auto wired beans using Intellij (I have version 9 Ultimate). Also Intellij has an option of making autowiring dependencies explicit. Link Provided below
http://blogs.jetbrains.com/idea/2009/03/making-spring-autowired-dependencies-explicit/
你使用什么IDE? Spring STS(一个基于 Eclipse 的 IDE)有很多用于处理 Spring 注释和自动装配的工具,以及一组很好的重构工具。
What IDE are you using? Spring STS (an Eclipse based IDE) has a lot of tools for working with Spring annotations and autowiring as well as good set of refactoring tools.