Announcement Announcement Module
Collapse
No announcement yet.
Dynamic configuration dependend on application context Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Dynamic configuration dependend on application context

    Hi,
    I have the problem that I have two web applications (both are the same) running in Tomcat which both needs different data storages for caching (OSCache is used). The initialisation of OSCache is done in the application-context:

    Code:
    <!-- Cache -->
    	<bean id="cacheAdministrator" class="com.opensymphony.oscache.general.GeneralCacheAdministrator" destroy-method="destroy">
    		<constructor-arg index="0">
    			<props>
    				<prop key="cache.memory">true</prop>
    				<prop key="cache.event.listeners">biz.solution4your.lms.cache.StatisticListenerImpl, com.opensymphony.oscache.extra.ScopeEventListenerImpl</prop>
    				<prop key="cache.persistence.class">com.opensymphony.oscache.plugins.diskpersistence.HashDiskPersistenceListener</prop>
    				<prop key="cache.persistence.overflow.only">true</prop>
    				<prop key="cache.path">${catalina.base}/temp/cache</prop>
    				<prop key="cache.capacity">100</prop>
    				<prop key="cache.unlimited.disk">false</prop>
    			</props>
    		</constructor-arg>
    	</bean>
    	<!-- /Cache -->
    As you can see, I am currently using "${catalina.base}/temp/cache" (this would be the same for both webapplications in Tomcat), but I like to know if I can also use the webapplication to make sure the caches are different for the different webapplications? E.g. something like this directory structure: "<tomcatbasepath>/temp/<applicationcontext>/cache". Any idea?

    TIA Octoate

  • #2
    If you include a bean in your context that implements ServletContextAware it will be wired with the context at startup. Then you can pull the context name out of the ServletContext (e.g. using a PropertyPathFactoryBean).

    Comment


    • #3
      As david suggested, use the ServletContext to add parameters as part of your web.xml. This way, you don't have to rely on the a system property (which is viewed by the entire VM) and you change things dynamically w/o much hassle.

      Comment

      Working...
      X