简体   繁体   English

还有什么可以在Java中用作ServiceLoader替代方案?

[英]What else can be used in Java as the ServiceLoader alternative?

I'm looking for something like the ServiceLoader, but which does not depend on SPI file, where all the service implementations should be enumerated and then added to the path of some class loader, in order to be found. 我正在寻找类似ServiceLoader的东西,但它不依赖于SPI文件,其中应枚举所有服务实现,然后将其添加到某个类加载器的路径中,以便找到它。

Let's say there is an application, that has the interface and some implementations of a service. 假设有一个应用程序,它具有接口和服务的一些实现。 What framework can be used, that allows you to add a new JAR to the application, which contains some new implementations and they can be automatically added to the class path of all the class loaders inside that application? 可以使用什么框架,允许您向应用程序添加新的JAR,其中包含一些新的实现,并且它们可以自动添加到该应用程序内所有类加载器的类路径中? All the class loaders is very important here, because if this is a NetBeans module application, the NetBeans platform does weird magic and you never know which class loader is used by which thread, with which class path etc... It would be also great, if the application does not need to be restarted to find the new JAR, but that's not an important requirement. 所有类加载器在这里都非常重要,因为如果这是一个NetBeans模块应用程序,那么NetBeans平台就会产生奇怪的魔力并且您永远不知道哪个类加载器被哪个线程使用,哪个类路径等...它也会很棒,如果不需要重新启动应用程序来查找新的JAR,但这不是一个重要的要求。

I already heard about OSGi, but this seems too big and I only need 1% of its features. 我已经听说过OSGi,但这看起来太大了,我只需要1%的功能。

Thanks for any suggestions! 谢谢你的任何建议!

Simplest solution is to use JSPF . 最简单的解决方案是使用JSPF

More "enterprise" one could be to use OSGi ... but in that case, you'll have to take a look at iPOJO , as an example. 更多的“企业”可能是使用OSGi ......但在这种情况下,你将不得不看一下iPOJO ,作为一个例子。 Sorry, I finally re-read your message. 对不起,我终于重新阅读了你的留言。 I think that, contrary to what you say, OSGi is exactly scopped for your need, as it precisely allows service loading and dynamic wiring. 我认为,与你所说的相反,OSGi正是为了满足你的需求,因为它精确地允许服务加载和动态布线。

And IoC containers may provide, with some extensions, that kind of feature (I think it's at least possible using a Guice extension). IoC容器可以通过一些扩展提供这种功能(我认为至少可以使用Guice扩展)。

似乎您正在寻找Netbeans Lookup API - Link

A newer alternative (this is an old question) might be sezpoz . 一个较新的选择(这是一个老问题)可能是sezpoz

Its very similar to the JDK ServiceLoader in that it uses a META-INF resource lookup except that the resources are automatically created by an annotation processor. 它与JDK ServiceLoader非常相似,它使用META-INF资源查找,但资源是由注释处理器自动创建的。 Thus its very annotation heavy and generally more type safe at the cost of post processing. 因此,它的注释很重,并且通常以后期处理为代价更安全。 Its used by Hudson/Jenkins. 它由Hudson / Jenkins使用。

I believe Kohsuke was the first to come up with this annotation processing idea: http://metainf-services.kohsuke.org/ 我相信Kohsuke是第一个提出这个注释处理理念的人: http//metainf-services.kohsuke.org/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM