spring resource in WEB-INF
I have a bean that has a property of type 开发者_开发问答File
. I want that property to end up pointing to a file under WEB-INF.
It seems to me that the ServletContextResourceLoader
should have that job, somehow, but nothing I try seems to do the job.
I'm trying to avoid resorting to something like this in the Java code.
If that property has to remain as type "File", then you're going to have to jump through some hoops.
It would be better, if possible, to refactor the bean to have a Resource
property, in which case you can inject the resource path as a String, and Spring will construct a ServletContextResource
for you. You can then obtain the File
from that using the Resource.getFile()
method.
public class MyBean {
private File file;
public void setResource(Resource resource) {
this.file = resource.getFile();
}
}
<bean class="MyBean">
<property name="resource" value="/WEB-INF/myfile">
</bean>
精彩评论