首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PaxExam和CmPropertyPlaceholder

PaxExam和CmPropertyPlaceholder
EN

Stack Overflow用户
提问于 2014-02-05 16:26:02
回答 1查看 578关注 0票数 2

我正在尝试实现PaxExam来测试骆驼路线的蓝图:

代码语言:javascript
复制
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
   xmlns:camel="http://camel.apache.org/schema/blueprint"
   xsi:schemaLocation="
   http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
   http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.0.0.xsd
   http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">

<cm:property-placeholder persistent-id="paxexam.HelloBean">
  <cm:default-properties>
    <cm:property name="greeter" value="Hey"/>
  </cm:default-properties>
</cm:property-placeholder>

<bean id="helloBean" class="me.examples.paxexam.HelloBean">
  <property name="say" value="${greeter} from Camel"/>
</bean>

[...]

如果包部署在Karaf中,它就能工作,但是当我试图在PaxExam测试中运行它时,当CmPropertyPlaceholder被初始化时,它会与NullPointerException一起失败:

代码语言:javascript
复制
Caused by: java.lang.NullPointerException
    at java.util.Hashtable.put(Hashtable.java:394)[:1.6.0_45]
    at org.apache.aries.blueprint.compendium.cm.CmPropertyPlaceholder.init(CmPropertyPlaceholder.java:102)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[:1.6.0_45]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)[:1.6.0_45]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)[:1.6.0_45]
    at java.lang.reflect.Method.invoke(Method.java:597)[:1.6.0_45]
    at org.apache.aries.blueprint.utils.ReflectionUtils.invoke(ReflectionUtils.java:225)[10:org.apache.aries.blueprint:0.3.2]
    at org.apache.aries.blueprint.container.BeanRecipe.invoke(BeanRecipe.java:838)[10:org.apache.aries.blueprint:0.3.2]
    at org.apache.aries.blueprint.container.BeanRecipe.runBeanProcInit(BeanRecipe.java:638)[10:org.apache.aries.blueprint:0.3.2]  

这是我的PaxExam配置方法:

代码语言:javascript
复制
@Configuration
public static Option[] configure() throws Exception {
  return new Option[] {
    karafDistributionConfiguration().frameworkUrl(getFrameworkUrl("karaf"))
    .karafVersion("2.2.11")
    .useDeployFolder(false)
    .unpackDirectory(new File("target/exam/unpack")),
    logLevel(LogLevel.INFO),
    keepRuntimeFolder(),
    replaceConfigurationFile("etc/activemq-broker.xml", new File("src/test/resources/activemq-broker-test.xml")),

    features(getKarafStandardFeaturesUrl(), "config", "http"),
    features(getActiveMqFeaturesUrl(), "activemq-blueprint", "activemq-camel"),
    features(getCamelFeaturesUrl(), "camel-core", "camel-blueprint", "camel-jms", 
                    "camel-cxf", "camel-test", "camel-jackson", "camel-quartz"),
    features(getSmixFeaturesUrl(), "saaj", "activemq-broker"),

    streamBundle(bundle().add(Hello.class)
        .add(HelloBean.class)
        .add("OSGI-INF/blueprint/blueprint.xml",
            new File("src/main/resources/OSGI-INF/blueprint/blueprint.xml").toURL())
        .set(Constants.BUNDLE_SYMBOLICNAME, "me.examples.paxexam")
    .set(Constants.IMPORT_PACKAGE, "org.osgi.service.blueprint,org.slf4j")
        .set(Constants.DYNAMICIMPORT_PACKAGE, "*")
    .build()).start()
  };
}

我需要做什么特殊的使用cm:属性占位符与PaxExam?(删除标记使测试运行良好)

提前准备好,干杯

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-02-06 08:34:09

这是卡拉夫的考试吗?如果是这样的话,您需要确保这些属性是可用的,您希望在配置管理服务中设置这些属性。如果这是一个普通的Pax考试测试,您需要确保ConfigurationAdmin服务可用。稍后请看一下这个样本

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21582754

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档