0

In Spring, bean initialization using XML supports resource loading using the classpath*: prefix (ant style)

<bean id="mapper" class="org.Class"
    scope="singleton">
    <property name="mappingFiles" value="classpath*:/mappings/*Mapping.xml" />
</bean> 

How do I achieve the same result when using @Bean annotation?

Nate Barbettini
  • 51,256
  • 26
  • 134
  • 147
Stuck in Java
  • 202
  • 2
  • 12
  • possible duplicate of [Inject files as list of resources using wildcard by annotations in Spring](http://stackoverflow.com/questions/24738402/inject-files-as-list-of-resources-using-wildcard-by-annotations-in-spring) – Andy Wilkinson Apr 09 '15 at 09:27
  • Yes Andy it is duplication of the one you referred . let me know if i need to delete this – Stuck in Java Apr 09 '15 at 16:07

1 Answers1

1

In any spring bean

@Value("classpath:myClasspathLocation") 
private Resource res;
Evgeni Dimitrov
  • 21,976
  • 33
  • 120
  • 145
  • Thank you for the Answer , with this approach we can read single file at a time, we have number of files with prefix Mapping.xml, and to avoid unnecessary code we would like to use same approach as in XML – Stuck in Java Apr 08 '15 at 17:56
  • Thank You again @Evgeni , below worked for me. @Value("classpath*:/mappings/*Mapping.xml") private Resource[] resources;' – Stuck in Java Apr 09 '15 at 16:05