2012-07-06 80 views

回答

3

你可以把这样的东西 - <terracottaConfig url="${terracotta.config.location}" />,但是大的渔获是,这将只加载from the system properties。它不是从PropertyPlaceHolder解析的,因为它不是Spring配置文件。

所以,如果你想使用外部配置文件,你会基本上都以编程方式设置此系统属性的Spring应用程序开始装载了ehcache.xml中文件之前 - 一个方法来做到这将是你的自定义ServletContextListener写加载你的属性文件并根据它设置系统属性,这样当ehcache.xml被加载时,它将能够正确地解析占位符。


您的回答帮助我解决了我的问题。我只想补充一点,而不是通过程序设置系统属性,我使用UTIL:属性如下

<bean id="sysProperties" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"> 
     <property name="targetObject" value="#{@systemProperties}"/> 
     <property name="targetMethod" value="putAll"/> 
     <property name="arguments"> 
      <util:properties> 
       <prop key="propertyname_used_in_ecache_xml">#{proerties_defined_using_property_factory['propertyname_defined_in_external_properties_file']}</prop> 
      </util:properties> 
     </property> 
    </bean> 

    <bean id="cacheManager" 
     class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" depends-on="sysProperties"> 
     <property name="configLocation"> 
      <value>classpath:ehcache.xml</value> 
     </property> 
    </bean> 
+0

这可能会实现,但我的要求是这样的,我想要加载“terracotta.config的价值。位置'从外部属性文件。我们可以通过扩展某些类让我们说'EhCacheFactoryBean'来实现这一点。 – JProgrammer 2012-07-09 20:44:00