[英]Does Aries managed-service-factory also manage properties?
I'm using Apache Aries 0.2 in Servicemix 4.3.1 and creating a cm:managed-service-factory. 我在Servicemix 4.3.1中使用Apache Aries 0.2并创建cm:managed-service-factory。 Creation of the services with .cfg files works fine (except for #ARIES-584 ), but the properties from the .cfg file do not get injected into the service object. 使用.cfg文件创建服务工作正常( #ARIES-584除外),但.cfg文件中的属性不会注入服务对象。 They do get set properly in ConfigAdmin, just my bean setter methods never get called for the values in my config file. 它们确实在ConfigAdmin中正确设置,只是我的bean setter方法永远不会调用我的配置文件中的值。
I was thinking I should maybe use a cm:managed-properties or something like that nested inside my managed-service-factory, but that would require a separate pid, so doesn't seem right. 我以为我应该使用cm:托管属性或类似嵌套在我的托管服务工厂中的东西,但这需要一个单独的pid,所以似乎不对。
If I don't put the property tag in, then no value ever gets set. 如果我没有放入属性标记,则不会设置任何值。 With the property tag, then just the default value gets set, but never the actual config file value. 使用属性标记,然后只设置默认值,但从不实际配置文件值。
I can't find any documentation for usage of the Aries CM subproject, except for blueprint-sample.xml , which doesn't show managed properties inside a managed service factory. 我找不到任何使用Aries CM子项目的文档,但blueprint-sample.xml除外,它没有显示托管服务工厂内的托管属性。 I've really been trying to use Servicemix, but around every corner there is missing documentation, broken or missing features, or bugs that affect core functionality. 我一直在尝试使用Servicemix,但是在每个角落都缺少文档,功能损坏或丢失,或者影响核心功能的错误。
Both the spring and gemini documentation indicate that their managed-service-factory implementations should also function as managed-properties. spring和gemini文档都指出他们的托管服务工厂实现也应该作为托管属性。
foo.xml: foo.xml:
<blueprint>
<cm:managed-service-factory id="myfoo-msf" factory-pid="my.msf" interface="my.IFoo">
<cm:managed-component class="my.Foo">
<property name="name" value="default />
</cm:managed-component>
</cm:managed-service-factory>
</blueprint>
IFoo.java IFoo.java
package my;
public interface IFoo {
public String getName();
public void setName(String name);
}
Foo.java Foo.java
package my;
public class Foo implements IFoo {
private String name;
public void setName(String name) {
this.name = name;
System.out.println("name set to: " + name);
}
public String getName() {
return name;
}
}
my.msf-1.cfg my.msf-1.cfg
name=name1
my.msf-2.cfg my.msf-2.cfg
name=name2
System.out System.out的
name set to default
name set to default
config:proplist 配置:proplist变种
service.pid = my.msf.xxxxxxx-xx-xx-xxxxxxxxxxxxxxx
name = name1
service.factoryPid = my.msf
service.pid = my.msf.yyyyyyy-yy-yy-yyyyyyyyyyyyyyy
name = name2
service.factoryPid = my.msf
I believe you have to add one extra line within your managed-component element. 我相信你必须在managed-component元素中添加一行。
<blueprint>
<cm:managed-service-factory id="myfoo-msf" factory-pid="my.msf" interface="my.IFoo">
<cm:managed-component class="my.Foo">
<cm:managed-properties persistent-id="" update-strategy="container-managed"/>
<property name="name" value="default />
</cm:managed-component>
</cm:managed-service-factory>
</blueprint>
The default value will indeed be overwritten whatever is in your cfg file. 确实会覆盖cfg文件中的默认值。 If it matters,the default property value setter will be invoked, followed by the same property setter with the value from the cfg. 如果重要,将调用默认属性值setter,然后使用cfg中的值调用相同的属性setter。
In this case I have used container-managed for update strategy. 在这种情况下,我使用容器管理更新策略。 But you could use component managed. 但是你可以使用组件管理。
This seems kind of redundant to me and in poor taste. 这对我来说似乎有点多余,而且味道很差。 Why do I need to set another managed-properties within my bean with a blank persistent id when I have already done so above? 为什么我需要在我的bean中使用空白持久性id设置另一个托管属性,而我已经在上面这样做了? Maybe there is a better way but this seems to work. 也许有更好的方法,但这似乎有效。
Also, there is no obvious way to affect the Service Properties that are advertised. 此外,没有明显的方法可以影响所公布的服务属性。 For example, we might want to have a convention that any cfg properties that start with service:xxx would be passed through to the Service properties. 例如,我们可能希望有一个约定,即以service:xxx开头的任何cfg属性都将传递给Service属性。
Update: The Apache Aries tests are pretty helpful. 更新:Apache Aries测试非常有用。 They can be found here http://aries.apache.org/downloads/currentrelease.html . 他们可以在这里找到http://aries.apache.org/downloads/currentrelease.html 。 In particular take a look at the one for configuration management, org.apache.aries.blueprint.cm . 特别要看一下配置管理的一个,org.apache.aries.blueprint.cm。 In the test folder it has some examples. 在测试文件夹中它有一些例子。 It shows that in addition to the cm:managed-properties child element within the cm:managed-component shown above, there is also an option to have a cm:cm-properties element within the service-properties. 它显示除了上面显示的cm:managed-component中的cm:managed-properties子元素之外,还有一个选项可以在service-properties中包含cm:cm-properties元素。
<service-properties>
<entry key="key" value="foo3" />
<cm:cm-properties persistent-id="" update="true"/>
</service-properties>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.