gpt4 book ai didi

hudson 中的 Java @extension - 何时以及为何

转载 作者:太空宇宙 更新时间:2023-11-04 07:25:27 24 4
gpt4 key购买 nike

当我们需要在java中为hudson使用@extension时,会出现什么情况?根据定义,用于类/方法,以便 hudson 可以自动找到 ExtensionPoints 的实现。

hudson 中的扩展点是什么?一个例子可以更好地描述理论。

最佳答案

我只看到 JAvaDoc 的内容:

Marks a field, a method, or a class for automatic discovery, so that Hudson can locate implementations of ExtensionPoints automatically.

(In contrast, in earlier Hudson, the registration was manual.)

In a simplest case, put this on your class, and Hudson will create an instance of it and register it to the appropriate ExtensionList.

If you'd like Hudson to call a factory method instead of a constructor, put this annotation on your static factory method. Hudson will invoke it and if the method returns a non-null instance, it'll be registered. The return type of the method is used to determine which ExtensionList will get the instance. Finally, you can put this annotation on a static field if the field contains a reference to an instance that you'd like to register.

This is the default way of having your implementations auto-registered to Hudson, but Hudson also supports arbitrary DI containers for hosting your implementations. See ExtensionFinder for more details.

<小时/>

您引用的示例 ( hudson.plugins.clearcase.ItemListenerImpl ) 是 Hudson ItemListener 的特殊情况.

关于hudson 中的 Java @extension - 何时以及为何,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18612407/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com