“组件架构”和“组件架构”之间的区别和“模块化架构”;
OSGi是模块化架构,JavaBeans是组件架构。 有什么区别?
OSGi is a modular architecture, JavaBeans is a component architecture.
What's the diff?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
OSGi 和 Java Bean 之间的主要区别在于类加载器的工作方式。在标准 .jar 文件或 EJB 中,rt.jar 文件或等效的 EJB 维护类路径。此外,如果您使用容器来部署应用程序,则可能有多个类路径维护机制,这会导致问题。因此,例如,当您创建 .war 文件时,通常会创建一个包含 .war 的所有 .jar 依赖项的 lib 目录。如果您的应用程序中只有一个 war 或 .jar,这还算不错。但想象一下一个大型企业部署,有 100 个 EJB,全部包含 apache-commons!您最终会得到 100 个 apache-commons 实例,它们都在同一个容器内运行,占用资源。
在 OSGi 中,您将每个 .jar 文件(我们将它们称为捆绑包,因为现在是 OSGi)部署到 OSGi 容器中。每个 .jar 文件都会公开(导出)它希望其他包使用的包,并且还标识捆绑包的版本。此外,每个捆绑包还明确声明(导入)它需要从其他捆绑包中运行的包。然后,OSGi 容器将管理所有这些导出并将它们与适当的导入相匹配。现在您已经为您想要使用的每个 EJB 提供了 apache-commons。您已经删除了 /lib 目录,现在您的应用程序占用的资源更少。
在您的问题中,您询问了组件架构和模块化架构之间的区别。模块化是指使每个捆绑包成为自己的部署单元并允许其与其他捆绑包通信而不是将它们全部打包到一个庞大的 .jar 文件中的过程。
The primary difference between OSGi and Java Beans is in how the classloader works. In a standard .jar file or EJB, the rt.jar file or EJB equivalent maintains the classpath. Additionally, if you are using a container to deploy your application into, you may have multiple classpath maintanance mechanisms which cause problems. As a result, when you make a .war file, for example, you usually create a lib directory with all of your .war's .jar dependencies. If you only have one war or .jar in your application, this isn't so bad. But imagine a large enteprise deployment with 100 EJB's all containing apache-commons! You end up with 100 instances of apache-commons all running inside the same container sucking up resources.
In OSGi, you deploy each .jar file (we'll call them bundles cuz this is OSGi now) into the OSGi container. Each .jar file exposes (exports) the packages it wants other packages to use, and also identifies the version of the bundle. Additionally, each bundle also expressly states (imports) the packages it needs from other bundles to work. The OSGi container will then manage all of these exports and match them up to the appropriate imports. Now you have apache-commons available to each of the EJB's you want to make available. You've done away with your /lib directory and now your application takes up less resources.
In your question you asked the difference between a component architecture and a modular architectures. Modularity refers to this process of making each bundle its own deployment unit and allowing it to talk to other bundles instead of balling them all up into one massive .jar file.