我已经使用以下ConfigurerAdapter添加了新的资源处理程序“外部上下文根”:
@Configuration
public class DynamicAssetsConfigurer extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/dynamicassets/**")
.addResourceLocations("file:/var/dynamicassets/");
super.addResourceHandlers(registry);
}
}
处理程序在向服务器发出请求时工作正常,但我想访问“/ dynamicassets / **”的内容作为资源。就像我可以访问“静态资产”(上下文根目录中的资产目录):
@Inject
private WebApplicationContext webContext;
public Resource[] getStaticAssetResources() {
// returns array of ServletResource objects
return webContext.getResources( "/assets/*.*");
}
public Resource[] getDynamicAssetResources() {
// this fails to get resources, because
// dynamicassets not found from context
return webContext.getResources( "/dynamicassets/*.*");
}
我如何访问“/ dynamicassets /”中的文件作为ServletResource对象?