configuration - 同一组件中的多种配置(@Meta.OCD接口(interface))

标签 configuration liferay osgi liferay-7

我有一个组件 MyComponent 需要访问 AConfiguration 和 BConfiguration:

my.MyComponent:

@Component(
    configurationPid = "[my.AConfiguration,my.BConfiguration]"
)
public class MyComponent {
    @Activate
    @Modified
    protected void activate(Map<String, Object> properties) {
        _aConfiguration = ConfigurableUtil
            .createConfigurable(AConfiguration.class, properties);
        _bConfiguration = ConfigurableUtil
            .createConfigurable(BConfiguration.class, properties);
    }

    public void hello() {
        System.out.println("A:" + _sConfiguration.valueA());
        System.out.println("B:" + _sConfiguration.valueB());
    }
}

my.A配置:

@Meta.OCD(
    id = "my.AConfiguration"
)
public interface AConfiguration {
    @Meta.AD(deflt = "6")
    public long valueA();
}

my.B配置:

@Meta.OCD(
    id = "my.BConfiguration"
)
public interface BConfiguration {
    @Meta.AD(deflt = "6")
    public long valueB();
}

问题:使用 Liferay 的配置 UI 将 valueA 和 valueB 配置为 7 没有效果,MyComponent.hello() 仍然看到默认值6

我做错了什么?
让我的组件使用来自多个配置接口(interface)的配置信息的正确方法是什么?

用例:我的组件执行一些业务处理并将结果保存到远程服务器。有一个配置接口(interface)包含业务处理设置,还有一个配置接口(interface)包含远程服务器的URL。

最佳答案

@Component 注释上的 configurationPid 属性格式错误。应该是:

configurationPid = { "my.AConfiguration", "my.BConfiguration" }

这将创建一个包含两个条目的字符串数组值:my.AConfigurationmy.BConfiguration。相反,您使用了:

configurationPid = "[my.AConfiguration,my.BConfiguration]"

...它创建一个单个字符串,其文字值为[my.AConfiguration,my.BConfiguration],这几乎肯定不是您想要的。

关于configuration - 同一组件中的多种配置(@Meta.OCD接口(interface)),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47935742/

相关文章:

python - 使用 argparse (python) 创建变量键/值对

spring-boot - 在 Kotlin 中迁移到版本 3+ 时,Spring Boot 无法再绑定(bind)配置属性

xml - 如何从 XML 配置文件设置 Spring 属性?

java - 在 Apache Karaf 3.0(OSGI 环境)中的 Atmosphere 上运行 Apache CXF

java - 我是否正确配置了 Hibernate hibernate.cfg.xml 文件?

jar - 如何在多个 portlet 中共享 jar?

java - Liferay - PreLoginAction - 阻止用户登录

tomcat - Liferay 发布结构 id 已经存在

java - org.osgi.framework.BundleException : Could not resolve module: org. eclipse.jetty.plus

osgi - XPage Osgi 插件开发