Announcement Announcement Module
Collapse
No announcement yet.
Spring 3.0 and Resource Injection Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring 3.0 and Resource Injection

    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 :
    Code:
    <bean id="myBean" class="...">
      <property name="template" value="some/resource/path/myTemplate.txt"/>
    </bean
    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.

    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 :
    Code:
    private @Resource ResourceLoader resourceLoader;
    But I would like to avoid the call to the API myself. So I do not want in my code the following line:

    Code:
    this.resourceLoader.getResource("classpath:application.properties");
    Is it possible?
Working...
X