Hi,
I am learning the concepts of Spring 3.0 and how to load a classpath resource.
Until Spring 2.5 I used to do something like this :
and this was automatically converted to an instance of Resource.java, thanks to the property editor registered with Spring container that did the job for us.Code:<bean id="myBean" class="..."> <property name="template" value="some/resource/path/myTemplate.txt"/> </bean
Now in Spring 3.0, I have my beans defined using the @Bean annotations.
What I want to achieve is the same behavior as was present in Spring 2.5, ie I provide a resource as a String while defining my bean and it gets converted to an instance of Resource. Is it possible?
I know I can achieve the same functionality by introducing a ResourceLoader field in my class and using the @Resource or @Inject annotations on it, so that Spring will automatically inject the ResourceLoader, which I can then use to get the instance of Resource. Something like this :
But I would like to avoid the call to the API myself. So I do not want in my code the following line:Code:private @Resource ResourceLoader resourceLoader;
Is it possible?Code:this.resourceLoader.getResource("classpath:application.properties");


Reply With Quote
