在<resources>标记</resources>中使用Spring bean值

时间:2014-03-28 16:03:50

标签: java spring spring-mvc

我们正在使用Spring 3.1.2并为客户端的东西定义了一个String bean:

<bean name="clientVersion" class="java.lang.String">
    <constructor-arg value="CLIENT_VERSION" />
</bean>

这可以用于我们bean中的各种事情。我希望能够在<resources>标记中使用它来映射我们的一些静态资源。我试过这个:

<resources mapping="/#{clientVersion}/**" location="/path/to/versioned/resources/#{clientVersion}/" />

它似乎适用于mapping属性。我在服务器启动时看到了这个:

INFO  o.s.w.s.h.SimpleUrlHandlerMapping - Mapped URL path [/CLIENT_VERSION/**] onto handler 'org.springframework.web.servlet.resource.ResourceHttpRequestHandler#2'

但是,当我实际点击CLIENT_VERSION下的网址(例如&#34; CLIENT_VERSION / all.js&#34;)时,我会在日志中看到这一点:

DEBUG o.s.w.s.h.SimpleUrlHandlerMapping - URI Template variables for request [/CLIENT_VERSION/all.js] are {}
DEBUG o.s.w.s.h.SimpleUrlHandlerMapping - Mapping [/CLIENT_VERSION/all.js] to HandlerExecutionChain with handler [org.springframework.web.servlet.resource.ResourceHttpRequestHandler@7dad45af] and 1 interceptor
DEBUG o.s.w.s.DispatcherServlet - Last-Modified value for [/CLIENT_VERSION/all.js] is: -1
DEBUG o.s.w.s.r.ResourceHttpRequestHandler - Trying relative path [all.js] against base location: ServletContext resource [/path/to/versioned/resources/#{clientVersion}/]
DEBUG o.s.w.s.r.ResourceHttpRequestHandler - No matching resource found - returning 404

我的猜测是它试图在/path/to/versioned/resources/#{clientVersion}/all.js找到该文件,因为该文件位于路径/ path / to / versioned /resources/CLIENT_VERSION/all.js,它找不到它。

location属性是否有办法像#{clientVersion}属性一样解析mapping?还有另一种方法可以实现这个目标吗?

0 个答案:

没有答案