使用wildfly 10进行Ehcache配置

时间:2017-05-10 07:51:27

标签: jboss wildfly ehcache

尝试使用wildfly10中的ehcache.xml实现ehcache

将ehcache.jar文件添加为模块并添加了依赖项,如下所述:

   <resources>
       <resource-root path="ehcache-1.2.2.jar"/> 
   </resources>

   <dependencies>
       <module name="org.apache.commons.logging"/>
       <module name="org.apache.log4j"/>
       <module name="javax.xml.parsers"/> 
   </dependencies>


</module>

当我尝试运行服务器war文件时,我收到以下错误。

  

从d:\ ehcache.xml配置时出错。最初的原因是从输入流配置错误。最初的原因是__redirected .__ SAXParserFactory无法强制转换为javax.xml.parsers.SAXParserFactory

任何领导都会有所帮助。

堆栈跟踪:

  • net.sf.ehcache.CacheException:从配置时出错 d:\的Ehcache \ ehcache.xml中。最初的原因是从配置错误 输入流。最初的原因是__redirected .__ SAXParserFactory
    无法转换为javax.xml.parsers.SAXParserFactory
    net.sf.ehcache.config.ConfigurationFactory.parseConfiguration(ConfigurationFactory.java:80) net.sf.ehcache.CacheManager.parseConfiguration(CacheManager.java:752) net.sf.ehcache.CacheManager.init(CacheManager.java:386)
    net.sf.ehcache.CacheManager。(CacheManager.java:295)
    MySqlTest.ehcache(MySqlTest.java:93)
    MySqlTest.processRequest(MySqlTest.java:77)
    MySqlTest.doGet(MySqlTest.java:224)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85) io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62) io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78) io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131) io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57) io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46) io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64) io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60) io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77) io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50) io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43) io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61) io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:284) io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:263) io.undertow.servlet.handlers.ServletInitialHandler.access $ 000(ServletInitialHandler.java:81) io.undertow.servlet.handlers.ServletInitialHandler $ 1.handleRequest(ServletInitialHandler.java:174) io.undertow.server.Connectors.executeRootHandler(Connectors.java:202) io.undertow.server.HttpServerExchange $ 1.run(HttpServerExchange.java:793) java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:617) java.lang.Thread.run(Thread.java:745)

2 个答案:

答案 0 :(得分:1)

你似乎使用了Ehcache 1.这个版本真的很老了。您至少应升级到Ehcache 2.最新版本是Ehcache 3.Ehcache 1很可能与您当前的Java版本和wildfly依赖项不兼容。

答案 1 :(得分:0)

它适用于EhCache 3.3.1

  1. 将ehcache-3.3.1.jar文件放入wildfly10_HOME \ modules \ system \ layers \ base \ org \ ehcache \ main

  2. 在上面的文件夹中编辑module.xml,如下所示

                                                                                                                   

  3. 代码:

  4. String cacheName =“basicCacheNamit”;

    try (CacheManager cacheManager = newCacheManagerBuilder()
      .withCache(cacheName,
        newCacheConfigurationBuilder(Long.class, String.class, heap(100).offheap(1, MB)))
      .build(true)) {
      Cache<Long, String> basicCache = cacheManager.getCache(cacheName, Long.class, String.class);
    
    
      basicCache.put(1L, "da one!");
      String value = basicCache.get(1L);