0
我在我的彈簧應用程序的類路徑中有一個目錄。如何使用ResouceLoader加載該目錄中的所有文件。彈簧框架:從類路徑加載所有資源
// bean for test context
public class DatabaseLoader {
@Autowired
protected ResourceLoader myLoader;
private Logger log = LoggerFactory.getLogger(this.getClass());
@PostConstruct
public void init() throws IOException, FileNotFoundException {
Resource[] resources = myLoader.getResource("classpath:fixtures/*.sql");
//codepopulate in memory db with all test fixtures
for (Resource r: resources) {
//populate in memory db with data in this resource.
}
}
}
看一看http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/ core/io/support/PathMatchingResourcePatternResolver.html – fateddy 2015-02-10 02:04:19
fateddy:任何代碼示例? – riship89 2015-02-11 18:45:12
找到下面的答案代碼示例。如果這解決了您的問題,請接受答案。 – fateddy 2015-05-09 18:14:22