2

It seems like there's been a few iterations of property support in spring it's hard to tell what's best practice and the manuals are written from the point of view of someone who is familiar with every other iteration. I feel like this should be a simple and common requirement but given how hard it's been please correct me if there's a more idiomatic way.

What I want is to pass an additional properties file to my spring web app based on a context property which the client is setting using a tomcat descriptor like so

<Context path="/foo" reloadable="true">
  <Parameter name="foo.config" value="file:${catalina.base}/conf/foo.properties"/>
</Context>

In spring for the live profile I have this

<beans profile="live">
            <context:property-placeholder location="classpath:timetabling.live.properties,${timetabling.config}" 
    ignore-resource-not-found="true" />
</beans>

So I'd assumed this doesn;t work because I'm trying to configure placeholder suppport with a placeholder. If I use a system property however then this works fine. I know that spring 3.1 has baked in support for system and environment properties so I guess my question is how can I augment this support with something context aware before the placeholder is resolved?

--Update--

looking at http://blog.springsource.org/2011/02/15/spring-3-1-m1-unified-property-management/ particularly at footnote 1, I would expect to have a DefaultWebEnvironment which should already have aceess to context init params. Now I am more confused, can someone provide me with a concrete example of context property retrieval? At this point I feel like I've read every javadoc available and they are just not helpful.

4

1 回答 1

0

<context:property-placeholder />设置从 .properties、系统属性和环境变量读取的PropertyPlaceholderConfigurer 。然而, Tomcatcontext.xml设置了一个 servlet 上下文初始化参数。所以你需要的是一个ServletContextPropertyPlaceholderConfigurer

于 2013-01-31T11:29:04.653 回答