Spring 3.0将文件注入资源 [英] Spring 3.0 inject files as resources

查看:160
本文介绍了Spring 3.0将文件注入资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Spring 3.0应用程序中,我在 / WEB-INF / dir 中有一些资源。在运行时,我需要其中一些作为 InputStream (或其他一些类型)。我该如何找回它们?是否可以将它们作为正常资源注入?

In my Spring 3.0 app, I have some resources in /WEB-INF/dir. At runtime I need some of them as an InputStream (or some other type). How can I retrieve them? Is it possible to inject them as a normal Resource?

推荐答案

这里通过注释是最简单的方法:

Here is an easiest way to do it via annotation:

import org.springframework.core.io.Resource;

@Value("classpath:<path to file>")
private Resource cert;

这篇关于Spring 3.0将文件注入资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆