我想为自定义资源前缀编写一个自己的Resource(来自core.io包)实现,例如“ myprotocol:/root/test/foo.properties”。
最初的想法是引用JCR存储库中的Apache Sling资源路径来加载一些属性文件,然后该属性文件可以由Spring应用程序上下文中的PropertyPlaceholderConfigurer使用,例如:
<context:property-placeholder properties-ref="appConfig" ignore-unresolvable="true" />
<bean id="appConfig" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<list>
<value>jcr:/app/test/foo.properties</value>
</list>
</property>
</bean>
有人知道如何实现吗?
谢谢你的帮助!奥利
资源路径的解析在DefaultResourceLoader类的getResource(String)方法中以固定方式执行,该方法是所有应用程序上下文的超类。
解决问题的一种方法是将应用程序上下文子类化。
public class CustomXmlApplicationContext extends AbstractXmlApplicationContext {
private final CustomResourceLocator customResourceLocator;
@Override
public Resource getResource(String location) {
Assert.notNull(location, "Location must not be null");
if (location.startsWith("custom:")) {
return customResourceLocator.getResource(location);
}
return super.getResource(location);
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句