1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
@Component public class ResourceLoaderContext implements ResourceLoaderAware { private ResourceLoader resourceLoader; @Override public void setResourceLoader(ResourceLoader resourceLoader) { this.resourceLoader = resourceLoader; } public ResourceLoader getResourceLoader() { return resourceLoader; } }
@Autowired private ResourceLoaderContext resourceLoaderContext;
@Test public void resourceLoaderTest() throws IOException { final Resource resource = resourceLoaderContext.getResourceLoader().getResource("file:/Users/zhenglin/learn-space/RuoYun/framework/src/main/java/zlin/site/framework/Foo.java"); try (final InputStream stream = resource.getInputStream()) { final String content = IOUtils.toString(stream); log.info(content); } }
|