gpt4 book ai didi

java - 如何启动 immediate = false 组件?

转载 作者:行者123 更新时间:2023-11-30 08:48:34 25 4
gpt4 key购买 nike

我有以下组件:

@Component(
label = "Service name",
description = "Service description",
metatype = true,
immediate = false)
@Properties({
@Property(
label = "My Label"
name = "property-name",
value = "my value",
propertyPrivate = true
)
})
@Service
public class SampleServiceImpl implements SampleService {
private final Logger log =
LoggerFactory.getLogger(this.getClass());

/**
* OSGi Properties *
*/
private static final String DEFAULT_SAMPLE = "hello!";
private String mySample = DEFAULT_SAMPLE;
@Property(label = "Prop name",
description = "Prop description",
value = DEFAULT_SAMPLE)
public static final String PROP_SAMPLE = "sample";

...

@Activate
protected void activate(final Map<String, String> config) {
mySample = PropertiesUtil.toString(config.get(PROP_SAMPLE), DEFAULT_SAMPLE);
}

@Deactivate
protected void deactivate(final Map<String, String> config) { }
}

是在cq启动后注册的。这是预期的行为。

如何开始?我找不到这个界面。

最佳答案

是的,这是非直接组件的预期行为。来自 a blog post作者:Felix Meschberger 在 dev.day.com 上,

The OSGi Declarative services specification defines three types of components:

  • Immediate Components are immediately created when the providing bundle is started and may or may not provide services

  • Delayed Components provide services but are only created when used by a service consumer.

  • Factory Components are created on demand by calling the ComponentFactory.newInstance(Dictionary) method of the Component Factory service registered for the component.

因此,如果您设置 immediate = false,您将拥有一个延迟组件,它由运行时按需激活 — 您不需要自己显式启动该组件。

您应该检查的主要内容是组件处于“已启用”或“已注册”状态(正如您提到的那样)而不是“不满意”(它找不到对它需要的依赖项)。

From the Felix documentation ……

STATE_REGISTERED

The Component has successfully been activated but is a Delayed or Service Factory Component pending instantiation on first use (value is 32).

关于java - 如何启动 immediate = false 组件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31860088/

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