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

相关推荐
星辰_mya几秒前
reids哨兵集群与选主
java·开发语言
BD_Marathon2 分钟前
SpringBoot快速入门
java·spring boot·后端
期待のcode3 分钟前
Java的多态
java·开发语言
lengjingzju14 分钟前
一网打尽Linux IPC(一):进程间通信完全指南——总体介绍
linux·服务器·c语言
阿豪学编程28 分钟前
【Linux】进程信号深度解析
linux·运维·服务器
证能量少女1 小时前
2026大专Java开发工程师,考什么证加分?
java·开发语言
FPGAI1 小时前
Java学习之基础概念
java·学习
芒克芒克1 小时前
Java集合框架总结(面试八股)
java·开发语言·面试
chenyuhao20241 小时前
Linux网络编程:HTTP协议
linux·服务器·网络·c++·后端·http·https
ejjdhdjdjdjdjjsl1 小时前
C#文件流操作技巧
java·开发语言·spring