我有以下课程
abstarct类:
@Component(componentAbstract = true)
public abstract class A implements SomeInterface{
@Reference
private ConfigurationManager manager;
@Activate
protected void activate(ComponentContext componentContext) {
manager.getTimeout();
}
}
第一个孩子:
@Component(
enabled = true,
immediate = true,
inherit = true,
metatype = true,
label = "***",
description = "***"
)
public class A1 extends A {...}
第二个孩子:
@Component(
enabled = true,
immediate = true,
inherit = true,
metatype = true,
label = "********",
description = "*************"
)
public class A2 extends A {...}
A
和A1
位于同一个捆绑包中,A2
位于另一个捆绑包中。
Apache Felix
实例化A1
manager.getTimeout();
行成功执行但A2
此行是NullPointeException
的原因。
如何解决这个问题?
更新
@Component(
enabled = true,
immediate = true,
metatype = true,
label = "***"
)
@Service(ConfigurationManager.class)
public class ConfigurationManager {
@Activate
protected void activate(ComponentContext componentContext) {
valueDelimiter = PropertiesUtil.toString(componentContext.getProperties().get(PROPERTY_VALUE_DELIMITER), PROPERTY_VALUE_DELIMITER_DEFAULT);
valueDelimiter = Pattern.quote(StringEscapeUtils.unescapeJava(valueDelimiter));//read value from osgi config
...
LOG.info("Service reconfigured: {}", toString());
}
}