super.addResourceHandlers(registry);
时间: 2024-06-13 13:05:00 浏览: 16
这段代码是在Spring MVC中配置静态资源的处理器。它的作用是将静态资源的访问路径和实际存储路径进行映射,使得在浏览器中访问静态资源时能够正确地获取到资源。其中,super表示调用父类的方法,addResourceHandlers是添加资源处理器的方法,registry是资源处理器的注册表。
代码示例:
```java
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
super.addResourceHandlers(registry);
registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
}
```
上述代码中,我们将访问路径为/static/**的请求映射到classpath:/static/目录下,即在浏览器中访问/static/**时,会自动寻找classpath:/static/目录下的资源并返回。
相关问题
protected void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/swagger-ui/**") .addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/"); super.addResourceHandlers(registry); }
这是一个在 Spring Boot 中添加 Swagger UI 的资源处理器的代码片段。它的作用是将 `/swagger-ui/**` 映射到 `classpath:/META-INF/resources/webjars/springfox-swagger-ui/` 目录下的 Swagger UI 资源。这样,当访问 `/swagger-ui` 路径时,就能够访问到 Swagger UI 页面。通过这个页面,我们可以查看和测试我们的 API 接口。同时,它也提供了一些方便的工具,如在线调试等。
public void addResourceHandlers(ResourceHandlerRegistry registry) { //访问路径 registry.addResourceHandler("/**") //映射真实路径 .addResourceLocations("classpath:/resources/") .addResourceLocations("classpath:/static/") .addResourceLocations("classpath:/admin/") .addResourceLocations("classpath:/front/") .addResourceLocations("classpath:/public/"); super.addResourceHandlers(registry); }这段代码是什么意思
这段代码是为了配置Spring MVC应用程序的资源处理器,它指定了静态资源的访问路径及其真实存储路径。具体而言,`addResourceHandler("/**")`指定了所有的请求路径都可以访问静态资源,`.addResourceLocations("classpath:/resources/")`指定了静态资源的存储路径为`classpath:/resources/`,`.addResourceLocations("classpath:/static/")`指定了静态资源的存储路径为`classpath:/static/`,类似地,`.addResourceLocations("classpath:/admin/")`、`.addResourceLocations("classpath:/front/")`和`.addResourceLocations("classpath:/public/")`分别指定了不同类型的静态资源的存储路径。
当浏览器请求某个静态资源时,Spring MVC会根据请求路径通过资源处理器去查找对应的静态资源,然后返回给浏览器。`super.addResourceHandlers(registry)`表示将资源处理器注册到Spring MVC配置中,以便生效。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)