项目外的 Spring Boot 自定义静态资源位置 [英] Spring Boot custom static resource location outside of project
本文介绍了项目外的 Spring Boot 自定义静态资源位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何添加自定义资源位置,例如位于名为 Resources 的文件夹中的 D 驱动器上.
How can I add a custom resource location that is on for example my D drive in folder called Resources.
@Configuration
public class StaticResourceConfiguration extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
super.addResourceHandlers(registry);
registry.addResourceHandler("/**").addResourceLocations("D:/Resources/");
}
}
这不起作用.
这是我的应用程序类,也是唯一的其他配置文件.
This is my application class and the only other configuration file.
@SpringBootApplication公共类应用程序{
@SpringBootApplication public class Application {
public static void main(String args[]){
SpringApplication.run(Application.class, args);
}
@Bean // for websocket endpoints
public ServerEndpointExporter serverEndpointExporter() {
return new ServerEndpointExporter();
}
@Bean
public PasswordEncoder bcryptPasswordEncoder(){
return new BCryptPasswordEncoder();
}
}
推荐答案
你应该使用 file
前缀说明你的位置,查看更多 此处.所以应该是
You should state your location using the file
prefix, check more here . So it should be
registry.addResourceHandler("/**").addResourceLocations("file:///D:/Resources/");
这篇关于项目外的 Spring Boot 自定义静态资源位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文