• Bug
  • Status: Closed
  • Resolution: Fixed
  • drb
  • Reporter: sourceforgetracker
  • September 21, 2009
  • 0
  • Watchers: 0
  • September 22, 2009
  • September 22, 2009

Description

The default configuration (where ehcache.xml is attempted to read off the classpath) should attempt to first use the context class loader for the current thread, if there is one. This is much more user friendly in situations where the ehcache JAR and ehcache.xml are loaded by different classloaders. For example, this is what log4j does in its auto-configuration mode.

Change is pretty simple, to Configuration.java:

/** * Configures a bean from an XML file in the classpath. */ public void configure(final Object bean) throws Exception { final SAXParser parser = SAXParserFactory.newInstance().newSAXParser(); final BeanHandler handler = new BeanHandler(bean); ClassLoader contextClassloader = Thread.currentThread().getContextClassLoader(); URL url = null; if (contextClassloader != null) { url = contextClassloader.getResource(DEFAULT_CLASSPATH_CONFIGURATION_FILE); } if (url == null) { url = getClass().getResource(DEFAULT_CLASSPATH_CONFIGURATION_FILE); } if (url != null) { if (LOG.isDebugEnabled()) { LOG.debug(“Configuring ehcache from ehcache.xml found in the classpath: “ + url); } } else { url = getClass().getResource(FAILSAFE_CLASSPATH_CONFIGURATION_FILE); if (LOG.isWarnEnabled()) { LOG.warn(“No configuration found. Configuring ehcache from ehcache-failsafe.xml” + “ found in the classpath: “ + url); } } parser.parse(url.toExternalForm(), handler); } Sourceforge Ticket ID: 1122734 - Opened By: nobody - 14 Feb 2005 22:16 UTC

Comments

Sourceforge Tracker 2009-09-21

Logged In: YES user_id=693320

Your change looks good. All tests pass. Change committed. Do you think you could write a test that fails without the change? Comment by: gregluck - 20 Mar 2005 01:33 UTC

Fiona OShea 2009-09-22

Re-opening so that I can properly close out these issues and have correct Resolution status in Jira