I am looking for a way to create custom ResourceLoader, that will use read from hbase table for the properties. I found that i can create my own ApplicationContext, override getResource and use my own ResourceLoader.
@Override
public Resource getResource(String location) {
if (location.startsWith(HbaseResource.HBASE_PREFIX) ) {
ResourceLoader loader = (ResourceLoader)getBean(HbaseResourceLoader.class);
return loader.getResource(location);
} else{
return super.getResource(location);
}
}
I’m looking for a way to get the same results, only using ClasspathXmlApplicationContext and not create my own contxt class.
Reading about ResourceLoaderAware i see this line:
As alternative to a ResourcePatternResolver dependency, consider
exposing bean properties of type Resource array, populated via pattern
Strings with automatic type conversion by the bean factory.
Can this help me in any way?
Is there another way i missed to register custom ResourceLoader?
ResourceLoader is kind of a special building block and can’t be directly injected like some other container services, but I believe your observation on the type conversion can help. You can install a ConversionService (with bean name “conversionService”) with some capabilities that suit you, and if you can make sure that it gets registered before any conversion needs to take place then I think it will work. How you do that depends on whether you use XML or @Configuration probably. A simple toy example: