java - Define variable in Spring config file to have access to external folder with images -
instead of having path variable (i.e. accessing images) in different parts of java spring controllers there way define variable in config file , use through such variable:
config file: string imagefolder = "d:\\projects\\project_name\\images\\"; spring controller: file outputfile = new file(imagefolder + img_name + "." + img_ext); imageio.write(image, img_ext, outputfile);
thaks in advance.
own solution (added in bottom):
web.xml:
<context-param> <param-name>imagefolder</param-name> <param-value>d:\projects\project_name\src\main\webapp\resource\images\</param-value> </context-param>
controller:
@restcontroller public class namecontroller { @resource private servletcontext servletcontext; @requestmapping(value = "/getimage/{img_name:.+}") public byte[] getimage(@pathvariable string img_name) throws internalerror { byte[] data; try { string imagefolder = servletcontext.getinitparameter("imagefolder"); string realpath = imagefolder + img_name; path path = paths.get(realpath); data = files.readallbytes(path); }catch (exception e){ data = null; } return data; } }
Comments
Post a Comment