Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring3: How to register my own resource prefix/protocol

I would like to write an own Resource (from the core.io package) implementation for a custom resource prefix, e.g. "myprotocol:/root/test/foo.properties".

The original idea is to reference an Apache Sling resource path in the JCR repository for loading some properties file which then may be used by the PropertyPlaceholderConfigurer in the Spring application context, e.g.:

<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>

Does anybody have an idea how to implement this?

Thanks for your help! Oli

like image 856
olibur Avatar asked Oct 21 '22 01:10

olibur


1 Answers

Since Spring 4.3 DefaultResourceLoader now has an addProtocolResolver() method that allows you to supply an implementation of the ProtocolResolver interface that takes a String and returns your implementation of ResourceLoader if you are able to load resources identified by the String value.

like image 188
Andy Brown Avatar answered Nov 03 '22 23:11

Andy Brown