2014-04-13 65 views
0

我有xml。 (Ehcache.xml) 我想從屬性文件(在類路徑上)注入屬性。將屬性注入非託管Spring xml

但是由於這個xml不是Spring託管bean,我無法這樣做。

任何建議如何克服這一點?

的XML:

... 
      properties="peerDiscovery=manual,rmiUrls=//**${other.node.hostname}**:41001/org.jasig.cas.ticket.ServiceTicket|//**${other.node.hostname}**:41001/org.jasig.cas.ticket.TicketGrantingTicket" 
      propertySeparator="," /> 



    <cacheManagerPeerListenerFactory 
      class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory" 
      properties="port=41001,socketTimeoutMillis=5000" /> 

</ehcache> 

我要注入$ {} other.node.hostname從另一個屬性文件。

,但我得到這個運行時:java.net.URISyntaxException:非法字符在當局在指數2:

所致// $ {} other.node.hostname:41001/org.jasig .cas.ticket.TicketGrantingTicket

謝謝, ray。

回答

0

在ehcache.xml中它不會工作,因爲它不是彈簧配置。但是,如果你在春天,而不是ehcache的文件中定義等效的配置它應該工作:

<context:property-placeholder location="classpath:config.properties"/> 

<bean id="myCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean"> 
    <property name="cacheManager" ref="cacheManager"/> 
    <property name="maxElementsInMemory" value="${cache.maxMemoryElements}"/> 
</bean> 

最好是使用ehcache.xml中的文件儘可能少的,並配置在春天的一切,因爲大多數的選項該文件具有相當的彈簧。

+0

但是,你將如何修改具有以下屬性的新的spring xml:cacheManagerPeerProviderFactory,cacheManagerPeerListenerFactory? – rayman