java应用程序中的java.lang.NoSuchMethoderror,它使用ehcache进行缓存实现

时间:2017-12-05 08:13:51

标签: ehcache-2

当我运行使用spring框架和ehcache进行缓存实现的java应用程序时,我面临以下错误。此应用程序基于IBM Integration Bus构建,Java和Spring框架。

完整的错误堆栈如下

+BIP2230E (Msg 2/4) MQJLMBRK ARCI511 147 ERROR DETECTED WHILST PROCESSI     
 NG A MESSAGE IN NODE 'ARFAL_MobilePortProtection01.FailureHandler.Tran     
 sform Failure'.                                                            
+BIP4367E (Msg 3/4) MQJLMBRK ARCI511 147 THE METHOD 'evaluate' IN JAVA      
 NODE 'FailureHandler.Transform Failure' HAS THROWN THE FOLLOWING EXCEP     
 TION: java.lang.NoSuchMethodError: org/ehcache/jcache/JCacheManager.ge     
 tEhCacheNativeCacheManager()Lnet/sf/ehcache/CacheManager;.                 
+BIP4395E (Msg 4/4) MQJLMBRK ARCI511 147 JAVA EXCEPTION: 'java.lang.NoS     
 uchMethodError'; THROWN FROM CLASS NAME: 'com.anz.common.cache.impl.Lo     
 calCacheHandler', METHOD NAME: 'getCacheManager', FILE: 'LocalCacheHan     
 dler.java', LINE: '99' 

触发错误的代码如下所示

/**
 * 
 */
package com.anz.common.cache.impl;

import java.io.File;
import java.lang.management.ManagementFactory;
import java.net.MalformedURLException;
import java.net.URL;

import javax.cache.Cache;
import javax.cache.configuration.MutableConfiguration;
import javax.management.MBeanServer;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.ehcache.jcache.JCacheManager;

import net.sf.ehcache.CacheException;
import net.sf.ehcache.management.ManagementService;

/**
 * ehCache Cache Handler in JCashe JSR107 standard API
 * Cache Handler Factory -> Cache Handler -> Caching Provider -> Cache Manager -> Cache
 * @author sanketsw
 * 
 */
public class LocalCacheHandler extends AbstractCacheHandler {

    private static final Logger logger = LogManager.getLogger();

    public static LocalCacheHandler _inst = null;



    public LocalCacheHandler() throws Exception {
        super();
    }

    /*public static LocalCacheHandler getInstance() throws Exception {
        if (_inst == null) {

                _inst = new LocalCacheHandler();
        }
        return _inst;
    }*/


    @Override
    public String getDefaultCacheName() {
        return "DefaultMap";
    }

    @Override
    public String getCachingProviderName() {
        return "org.ehcache.jcache.JCacheCachingProvider";
    }

    /* (non-Javadoc)
     * @see com.anz.common.cache.impl.AbstractCacheHandler#getCache(java.lang.String)
     */
    @Override
    public Cache<String, String> getCache(String cacheName) throws CacheException, Exception {
        Cache<String, String> cache = null;

        try {

            //logger.debug("Retriving cache {}", cacheName);
            cache = cacheManager.getCache(cacheName);   

        } catch(Exception e) {
            //logger.debug("Retriving cache using type classes {}", cacheName);
            try {
                cache = cacheManager.getCache(cacheName, String.class, String.class);
            }catch(Exception e2) {
                logger.throwing(e2);
            }
        }
        if (cache == null) {
            //logger.debug("Starting cache {}", cacheName);
            MutableConfiguration<String, String> jcacheConfig = new MutableConfiguration<String, String>();
            jcacheConfig.setTypes(String.class, String.class);          
            cache = cacheManager.createCache(cacheName, jcacheConfig);
        }
        return cache;
    }

    /* (non-Javadoc)
     * @see com.anz.common.cache.impl.AbstractCacheHandler#getCacheManager()
     */
    @Override
    public javax.cache.CacheManager getCacheManager() throws Exception {
        javax.cache.CacheManager ret =  super.getCacheManager();

        try {
            // Register for JMX management
            JCacheManager ehCacheManager = (JCacheManager)ret;
            MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
            ehCacheManager.getEhCacheNativeCacheManager().setName("LocalCacheManager");
            //logger.info("printing mBeanServer {}", mBeanServer);
            //logger.info("printing EhCacheNativeCacheManager {}", ehCacheManager.getEhCacheNativeCacheManager());
            ManagementService.registerMBeans(ehCacheManager.getEhCacheNativeCacheManager(), mBeanServer, true, true, true, true);
        }catch(Exception e) {
            //logger.info("net.sf.ehcache:type=CacheManager,name=LocalCacheManager is already registered for JMX management. Ignoring...");
            //logger.info(e.getMessage());
        }

        return ret;
    }

    @Override
    public String getCacheManagerURI() {
        String path =  System.getenv("CACHE_CONFIG");
        //logger.info("System property CACHE_CONFIG={}",path);
        File configFile = new File(path + "/" + "ehcache-localcache.xml");
        if(configFile.exists()) {
            try {
                return configFile.toURI().toURL().toString();
            } catch (MalformedURLException e) {
                logger.throwing(e);
            }
        } else {
            URL resource = LocalCacheHandler.class.getResource("ehcache-localcache.xml");
            if(resource != null) {
                //logger.warn("Loading a backup config file={}",resource);
                return resource.toString();
            }
        }
        //logger.warn("Could not load the resource {}", "ehcache-localcache.xml");        
        return null;
    }







}

任何可能是问题的线索。

0 个答案:

没有答案