Flowryn
Flowryn

Reputation: 1447

How to inject properties in ehcache configuration file?

Is it possible to inject some properties in ehcache.xml?

For example I have different property files, each belonging to an environment:

my_project_name.local.properties

my_project_name.test.properties

my_project_name.int.properties

my_project_name.prod.properties

each of them containing properties for a different environment.

I'd like to inject in ehcache.xml the property maxByteslocalHeap as following:

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:noNamespaceSchemaLocation="ehcache.xsd"
     updateCheck="false" monitoring="autodetect"
     maxBytesLocalHeap="${my_project.cache.maxBytesLocalHeap}">
     .....
</ehcache>

my_project.cache.maxBytesLocalHeap is defined in each property file shown above and has different values according to the environment where my application is running.

Upvotes: 2

Views: 2911

Answers (1)

Louis Jacomet
Louis Jacomet

Reputation: 14500

The short answer is no, across all existing Ehcache version at this time (latest 2.10.2 and 3.1.3).

The long answer to your question depends on the Ehcache version:

  • Ehcache 2.6.x to 2.10.x only supports property substitution for the disk path configuration at the CacheManager level. The pattern to use is the classical ${my.prop}.
  • Ehcache 3.0.0 up to 3.1.2 does not support any property substitution.
  • Ehcache 3.1.3 and above support property substitution in all schema position that accept text. Again, the pattern to use is the classical ${my.prop}. Note that it means with your example, you will not be able to substitute sizing information because the XSD enforces that the value is a strictly positive number.

The latest limitation listed here could be lifted - the development team was just not sure it was worth the effort. So if this is something you believe Ehcache should provide, please drop a mail on the ehcache-users google group.

Upvotes: 4

Related Questions