首页>>后端>>SpringBoot->Springboot配置图片虚拟映射

Springboot配置图片虚拟映射

时间:2023-11-30 本站 点击:0

1.新建一个MyWebAppConfigurer 配置静态资源需要映射的位置、建议把addResourceLocations的路径写在application.yml中、方面以后部署的打包修改配置文件的时候做外部配置文件加载、方面修改。这边为了节约时间就在代码中写了。

packageio.renren.config;importorg.springframework.context.annotation.Configuration;importorg.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;importorg.springframework.web.servlet.config.annotation.WebMvcConfigurer;/****@authorlyy*2021.11.21*///springboot2.x配置@ConfigurationpublicclassMyWebAppConfigurerimplementsWebMvcConfigurer{@OverridepublicvoidaddResourceHandlers(ResourceHandlerRegistryregistry){registry.addResourceHandler("/image/**").addResourceLocations("file:C:\Users\Administrator\Desktop\11月毕设\");}}

2.没有加权限控制的话直接通过IP+端口+项目名以及addResourceHandler中的路径就可以访问了、有权限控制的话需要权限放心或放在static静态资源文件夹下。个人用的shiro权限、所以需要放行。

@Bean("shiroFilter")publicShiroFilterFactoryBeanshiroFilter(SecurityManagersecurityManager){ShiroFilterFactoryBeanshiroFilter=newShiroFilterFactoryBean();shiroFilter.setSecurityManager(securityManager);//oauth过滤Map<String,Filter>filters=newHashMap<>();filters.put("oauth2",newOAuth2Filter());shiroFilter.setFilters(filters);Map<String,String>filterMap=newLinkedHashMap<>();filterMap.put("/webjars/**","anon");filterMap.put("/druid/**","anon");filterMap.put("/app/**","anon");filterMap.put("/sys/login","anon");filterMap.put("/swagger/**","anon");filterMap.put("/v2/api-docs","anon");filterMap.put("/swagger-ui.html","anon");filterMap.put("/swagger-resources/**","anon");filterMap.put("/captcha.jpg","anon");filterMap.put("/image/**","anon");filterMap.put("/**","oauth2");shiroFilter.setFilterChainDefinitionMap(filterMap);returnshiroFilter;}

3.映射成功、访问http://localhost:8080/renren-fast/image/v2-4f45411c72eb128a6085fc8173286ffc_1440w.jpg

作者:Java李杨勇


本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:/SpringBoot/4389.html