Java设置服务器图片

现做app需要用到图片,但不想放到app项目代码中,于是想到设置服务器图片,app中设置访问路径,加载图片,路径也可以设置为变量,方便变更

服务器代码添加类

package hs.hsapp.util;

import org.springframework.context.annotation.Configuration;

import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;

import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration

public class ResourcesConfig implements WebMvcConfigurer {

@Override

public void addResourceHandlers(ResourceHandlerRegistry registry) {

/** 通过url访问项目外的目录图片*/

registry.addResourceHandler("/mgg/**").addResourceLocations("file:E://tmpimg/");

}}

创建本地目录e://tmpimg, 用于存放图片文件

mgg 访问路径, e://tmpimg图片物理路径

Security配置类 添加类型过滤
重启服务,访问测试

https://localhost: 8080/mgg/denglu.jpg

相关推荐
zhixingheyi_tian5 分钟前
Linux/Windows 免密登录
linux·运维·服务器
Uso_Magic5 分钟前
SQLSERVER__EXPLAIN 常用分析案例。
服务器·数据库·sql
guygg8811 分钟前
基于数据驱动的模型预测控制电力系统机组组合优化MATLAB实现
开发语言·matlab
lly20240612 分钟前
组合模式:深入理解与实际应用
开发语言
2501_9083298517 分钟前
C++中的备忘录模式
开发语言·c++·算法
尤老师FPGA26 分钟前
petalinux制作linux系统flash+sd卡启动
linux·运维·服务器
左左右右左右摇晃28 分钟前
Java笔记——JMM
java·后端·spring
Schengshuo32 分钟前
Spring学习——新建module模块
java·学习·spring
qq_4160187241 分钟前
C++与机器学习框架
开发语言·c++·算法
Memory_荒年42 分钟前
Nacos双面超人:注册中心 + 配置中心,一个都不能少!
java·后端·架构