Spring WebContent Resources - Access outside Servl

2019-08-11 05:07发布

I have a Spring Web MVC application that I'd like to serve a large, partially generated file.

I've added that file to my WebContent directory and all works fine there. However, I'd also like to access that file from my various build/deploy scripts, which read and parse the file.

My current approach is to keep a copy of the file under the src directory as well as the WebContent directory. When serving the file from the web, it uses WebContent.

When serving the file for the build scripts, it uses the following spring config:

  <bean id="ringCodeData" class="com.myapp.data.RingCodeData">
     <property name="rulesInputFile" value="classpath:resources/rules_copy.xml" />
     <!-- <property name="rulesInputFile" value="classpath:../WebContent/rules.xml" />    -->
     <!-- <property name="rulesInputFile" value="file:/WebContent/rules.xml" /> -->
  </bean>

As you can see, I've tried several different approaches to get the two to refer to the same file (without resorting to copies).

File paths don't seem to work since they're based on the current directory, that changes based on whether I call a given utility class from Eclipse or from the build scripts.

How can I get these to refer to the same file?

The only other thought I have at the moment is to try to setup Spring MVC to stream the file from the classpath directory.

1条回答
在下西门庆
2楼-- · 2019-08-11 05:44

Your best bet is likely placing it in /WEB-INF/classes (or, if you're using an IDE, just the project's src/source folder) and use <jsp:include> to include it.

<jsp:include page="/WEB-INF/classes/resources/rules_copy.xml" />
查看更多
登录 后发表回答