java关于jar依赖关系的问题

发布于 2024-11-07 09:06:31 字数 571 浏览 0 评论 0原文

我有一个项目,其主要部分(例如 main.jar)依赖于作为不同的单独项目创建的库(例如 u1.jar、u2.jar 等)。
因此,人们可以在其他地方重用该库,即实用程序库和主要部分之间不存在依赖关系。
当然,主要部分依赖于库,但这没关系。
现在我需要在其中一个库中添加特定功能。
所需的功能已经实现。
它是通过 spring bean 实现的,用户可以配置实现在运行时的行为方式。
spring 应用程序上下文是通过主项目创建和使用的,因此我无权访问 spring 上下文 来自实用程序库。
问题是我想重用这个实现(而不是重复代码)并且不可能将该部分移到其他地方
我想到的是在这个特定的 util jar 中创建一个依赖项来引用 main.jar。
我将这样做是为了能够从实用程序 jar 访问 spring 上下文。
我担心的是,现在 main.jar 和 util.jar 之间存在循环依赖关系。
即 main.jar 已经依赖于 util.jar,现在我也将创建一个反向依赖。
这是一个好主意吗?或者我遇到麻烦了(类加载问题等)?
对于此类问题有好的方法吗?

谢谢

I have a project that its main part (e.g. main.jar) depends on libraries (e.g. u1.jar, u2.jar etc) that has been created as distinct separate projects.
So one could reuse the library elsewhere i.e. there is no dependency between the utility libraries and the main part.
The main part has dependencies on the libraries of course but this is ok.
Now I need to add a specific functionality in one of the libraries.
The needed functionality is already implemented.
It is implemented via a spring bean and the user can configure how the implementation will behave at runtime.
The spring application context is created and used only via the main project and so I do not have access to the spring context
from the utility libraries.
The problem is that I would like to reuse this implementation (and not duplicate the code) and it is not possible to move that part elsewhere
What comes to mind is to create a dependency in this specific util jar to refer to the main.jar.
I will do this to be able to have access to the spring context from the utility jar as well.
What concerns me is that now, I have a cyclic dependency between main.jar and util.jar.
I.e. main.jar already depends on util.jar and now I will create a reverse dependecy as well.
Is this a good idea to do it? Or am I into trouble (class loading issues etc)?
Is there a nice approach for these kind of issues?

Thanks

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

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

发布评论

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

评论(2

奈何桥上唱咆哮 2024-11-14 09:06:31

创建一个接口并让 util.jar 使用 main.jar 传递简单包装此上下文的实现的接口?

循环依赖看起来就像一场噩梦。你会先建造哪一个?

create an interface and let util.jar work with interface with main.jar passing the implementation which simply wraps this context?

cyclic dependency looks like a nightmare. Which one will you build first?

时常饿 2024-11-14 09:06:31

一旦发现存在循环依赖,您就知道设计中存在问题。您是否考虑过是否可以应用观察者模式?或者尝试阅读这篇关于非循环关系的文章

Once you see that you have cyclic dependency, you know that you have something wrong in the design. Have you thought about if you can apply the Observer Pattern ? Or try to read this one about Acyclic Relationships

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