3
我需要从Mule FunctionalTestCase访问Spring属性占位符属性。从Mule FunctionalTestCase获取安全的弹簧属性
我使用的是secure属性占位符,它是spring属性占位符的包装,因此无法在我的测试用例中手动加载属性。
有没有办法让他们从骡马上下文?所以我可以得到解密值?
我需要从Mule FunctionalTestCase访问Spring属性占位符属性。从Mule FunctionalTestCase获取安全的弹簧属性
我使用的是secure属性占位符,它是spring属性占位符的包装,因此无法在我的测试用例中手动加载属性。
有没有办法让他们从骡马上下文?所以我可以得到解密值?
它可以完成,但您将不得不创建并添加使用BeanFactory查找属性值的properties accessor helper bean。在此之后,您可以从Mule上下文获取该bean并使用它来检索属性值。
PropertiesAccessor propertiesAccessor = muleContext.getRegistry().get("propertiesAccessor");
Assert.assertEquals("expectedvalue", propertiesAccessor.getProperty("key"));
如果你不希望有PropertiesAccessor豆在您的生产代码,你可以把这个定义成一个单独的XML文件。
<?xml version="1.0" encoding="UTF-8"?>
<spring:beans xmlns:context="http://www.springframework.org/schema/context"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-current.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
">
<context:annotation-config />
<spring:bean id="propertiesAccessor" class="PropertiesAccessor" />
</spring:beans>
然后用你的主骡子配置XML一起加载,在你的FunctionalTestCase
@Override
protected String[] getConfigFiles() {
return new String[] {
"src/main/app/mule-config.xml",
"src/test/resources/propertiesAccessor.xml",
};
}