Search code examples
springwebsphereehcache

Can I use Websphere with Spring 3.1 and Ehcache?


I need to implement Ehcache in a project that uses Spring version 3.1 and Websphere. I tried to google something about this topic but I could'nt find anything. Have you guys ever used those three tools together? Thanks in advance.


Solution

  • As per EhCache docs,It will NOT detect Websphere Transaction Manager automatically,.

    Automatically Detected Transaction Managers

    Ehcache automatically detects and uses the following transaction managers in the following order:

    • GenericJNDI (e.g. Glassfish, JBoss, JTOM and any others that register themselves in JNDI at the standard location of java:/TransactionManager
    • Weblogic (since 2.4.0)
    • Bitronix
    • Atomikos

    No configuration is required; they work out of the box. The first found is used.

    And you can configure it as below.

    If your Transaction Manager is not in the above list or you wish to change the priority, provide your own lookup class based on an implementation of net.sf.ehcache.transaction.manager.TransactionManagerLookup and specify it in place of the DefaultTransactionManagerLookup in ehcache.xml:

    <transactionManagerLookup
      class= "com.mycompany.transaction.manager.MyTransactionManagerLookupClass"
      properties="" propertySeparator=":"/>
    

    And to integrate & Use Spring with EhCache, refer this link

    From Spring docs,

    36.3 Declarative annotation-based caching For caching declaration, the abstraction provides a set of Java annotations:

    @Cacheable triggers cache population @CacheEvict triggers cache eviction

    @CachePut updates the cache without interfering with the method execution

    @Caching regroups multiple cache operations to be applied on a method

    @CacheConfig shares some common cache-related settings at class-level