Spring web应用程序中的ehcache.xml文件中有此标签<terracottaConfig url="host1:9510,host2:9510,host3:9510"/>
。我想将这个标签的url属性外部化。 URL的值应该由来自外部文件的属性替换。如果你提出解决这个问题的任何解决方案,这将会非常有帮助。在Spring框架内部ehcache.xml文件中外化terracottaconfig属性
2
A
回答
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>
相关问题
- 1. Spring:外部和内部属性文件
- 2. Externarlize ehcache.xml以使用来自外部属性文件的属性
- 3. Angular 2外部化(属性文件)
- 4. Spring Boot的外化属性
- 5. Spring Boot外部属性文件(带有配置文件)?
- 6. 使用Spring以外的属性文件
- 7. 加载外部属性文件中UDF
- 8. Spring框架:按名称搜索属性
- 9. Spring PropertyPlaceHolder Java配置外部属性文件
- 10. C#内部静态外部与InternalCall属性 - 内部或外部?
- 11. Spring Boot嵌入式Tomcat无法在ApplicationListener中加载外部属性文件
- 12. 如何在java中使用属性文件在框架中?
- 13. 将外部属性注入到Spring上下文中
- 14. 春天引导属性文件外化
- 15. 在Spring Boot中读取属性文件
- 16. 从外部Jar加载属性文件
- 17. 缝i18n属性文件从外部罐
- 18. Java - 加载外部属性文件 - FileNotFoundException
- 19. 外部属性文件与JSF2
- 20. 春豆初始化使用外部属性文件的地图
- 21. 使用外部参数的实体框架自定义属性
- 22. 使用Spring LDAP获取内部属性
- 23. 在本地属性文件中覆盖Spring 3.1中的属性
- 24. jquery在外部框架
- 25. 如何使用Spring框架将属性文件中的值转换为Map?
- 26. 在Spring MVC中外部化logback.xml
- 27. 如何在kango框架中加载外部文件(html,js,css)
- 28. 在窗口小部件“内容”属性的HTML格式中使用框属性
- 29. 动态框架内部生成的框架文件夹
- 30. Spring框架中的切入点如何在内部工作
这可能会实现,但我的要求是这样的,我想要加载“terracotta.config的价值。位置'从外部属性文件。我们可以通过扩展某些类让我们说'EhCacheFactoryBean'来实现这一点。 – JProgrammer 2012-07-09 20:44:00