交付右手
2013-04-15 12:13
浏览 374
已采纳

spring 和 Ehcache web做页面缓存配置出异常?

项目用的是spring mvc + hibernate 的结构。现在想用 Ehcache web做一个简单的页面缓存。网上找了很多例子但是就是报异常:

Caused by: net.sf.ehcache.CacheException: Error configuring from file:/D:/workspace/sulai/webapp/WEB-INF/classes/ehcache.xml. Initial cause was Error configuring from input stream. Initial cause was null:90: Element <ehcache> does not allow nested <transactionManagerLookup> elements.
    at net.sf.ehcache.config.ConfigurationFactory.parseConfiguration(ConfigurationFactory.java:95)
    at net.sf.ehcache.config.ConfigurationFactory.parseConfiguration(ConfigurationFactory.java:131)
    at net.sf.ehcache.CacheManager.parseConfiguration(CacheManager.java:241)
    at net.sf.ehcache.CacheManager.init(CacheManager.java:190)
    at net.sf.ehcache.CacheManager.<init>(CacheManager.java:183)
    at net.sf.ehcache.CacheManager.create(CacheManager.java:343)
    at net.sf.ehcache.CacheManager.getInstance(CacheManager.java:364)
    at net.sf.ehcache.constructs.web.filter.SimplePageCachingFilter.getCacheManager(SimplePageCachingFilter.java:100)
    at net.sf.ehcache.constructs.web.filter.CachingFilter.doInit(CachingFilter.java:83)
    at net.sf.ehcache.constructs.web.filter.Filter.init(Filter.java:191)
    ... 27 more

 这是我的web.xml,是按照网上例子搞的。

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
   version="2.5">
   <!-- Shiro Filter -->
   <filter>
    <filter-name>shiroFilter</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    <init-param>
        <param-name>targetFilterLifecycle</param-name>
        <param-value>true</param-value>
    </init-param>
   </filter>
   <filter-mapping>
    <filter-name>shiroFilter</filter-name>
    <url-pattern>/*</url-pattern> 
   </filter-mapping>
   <!-- 异常处理过滤器拦截所有请求/* 或可改成*.action -->
   <filter> 
        <filter-name>SulaiExceptionFilter</filter-name> 
        <filter-class>com.sulai.core.exception.filter.SulaiExceptionFilter</filter-class> 
        <init-param> 
            <param-name>errorPage</param-name> 
            <param-value>/jsp/error/error.jsp</param-value> 
        </init-param> 
    </filter> 
    <filter-mapping> 
        <filter-name>SulaiExceptionFilter</filter-name> 
        <url-pattern>/*</url-pattern> 
    </filter-mapping>
    <!-- Ehcache web 页面缓存过滤器 -->
    <filter>  
       <filter-name>PageCacheFilter</filter-name>  
       <filter-class>net.sf.ehcache.constructs.web.filter.SimplePageCachingFilter</filter-class>  
    </filter>  
    <filter-mapping>  
       <filter-name>PageCacheFilter</filter-name>  
       <url-pattern>/*</url-pattern>  
    </filter-mapping>
   <!-- spring MVC 配置 -->
   <servlet>
    <servlet-name>spring</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <!-- 自定义servlet.xml配置文件的位置和名称,默认为WEB-INF目录下,名称为[<servlet-name>]-servlet.xml,如spring-servlet.xml -->
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:spring-servlet.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
   </servlet>
   <servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>*.action</url-pattern>
   </servlet-mapping>
   <!-- DWR ScriptSession过滤器 -->
    <servlet>
        <servlet-name>initScriptSessionListener</servlet-name>
        <servlet-class>
            com.sulai.message.util.InitScriptSession
        </servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <!--dwr servlet-->
    <servlet>
        <servlet-name>dwr-invoker</servlet-name>
        <servlet-class>
            org.directwebremoting.servlet.DwrServlet
        </servlet-class>
        <init-param>
            <param-name>debug</param-name>
            <param-value>true</param-value>
        </init-param>
        <init-param>
             <param-name>crossDomainSessionSecurity</param-name>
             <param-value>false</param-value>
        </init-param>
      <init-param>
            <param-name>allowScriptTagRemoting</param-name>
            <param-value>true</param-value>
      </init-param> 
        <init-param>
            <param-name>pollAndCometEnabled</param-name>
            <param-value>true</param-value>
        </init-param>
        <init-param>
            <param-name>activeReverseAjaxEnabled</param-name>
            <param-value>true</param-value>
        </init-param>
        <init-param>
            <param-name>org.directwebremoting.extend.ServerLoadMonitor</param-name>
            <param-value>org.directwebremoting.impl.PollingServerLoadMonitor</param-value>
        </init-param>
        <init-param>
            <param-name>disconnectedTime</param-name>
            <param-value>60000</param-value> 
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>dwr-invoker</servlet-name>
        <url-pattern>/dwr/*</url-pattern>
    </servlet-mapping>
    <!-- Spring log4j加载 -->
    <context-param>
        <param-name>webAppRootKey</param-name>
        <param-value>webapp.root</param-value>
   </context-param>
   <context-param>    
        <param-name>log4jConfigLocation</param-name>    
        <param-value>classpath:log4j.xml</param-value>
    </context-param>       
    <context-param>    
        <param-name>log4jRefreshInterval</param-name>    
        <param-value>60000</param-value>    
    </context-param> 
    <listener>    
        <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>    
    </listener>
   <!-- Spring配置 -->
   <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
   </listener>
   <!-- 定时器servletContext加载 -->
   <listener>
    <listener-class>com.sulai.util.jobs.JobContextListener</listener-class>
   </listener>
   <!-- 指定Spring Bean的配置文件所在目录。默认配置在WEB-INF目录下 -->
   <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        classpath:applicationContext.xml,
        classpath:applicationContext-dao.xml,
        classpath:applicationContext-shiro.xml,
        classpath:messages.xml
    </param-value>
   </context-param>
   <filter>
    <filter-name>Set Character Encoding</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>  
        <param-name>encoding</param-name>  
        <param-value>utf8</param-value>  
    </init-param>
   </filter>
   <filter-mapping>  
    <filter-name>Set Character Encoding</filter-name>  
    <url-pattern>/*</url-pattern>  
   </filter-mapping>
   <filter>
    <filter-name>UrlRewriteFilter</filter-name>
    <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
    </filter>
   <filter-mapping>
    <filter-name>UrlRewriteFilter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
   </filter-mapping>
   <!-- 404 自定义页面 -->
   <error-page>  
       <error-code>404</error-code>  
       <location>  
         /jsp/error/error.jsp
       </location>  
    </error-page>
   <welcome-file-list>
    <welcome-file>index.action</welcome-file>
  </welcome-file-list>
</web-app>

 这是 ehcache.xml

<?xml version="1.0" encoding="UTF-8"?>


<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="ehcache.xsd"
         updateCheck="true" monitoring="autodetect"
         dynamicConfig="true">


    <diskStore path="D:\\workspace\\sulai\\webapp\\pageCache"/>

    <cacheManagerEventListenerFactory class="" properties=""/>

    <defaultCache
            maxElementsInMemory="1000"
            eternal="false"
            timeToIdleSeconds="120"
            timeToLiveSeconds="120"
            overflowToDisk="true"
            maxElementsOnDisk="10000"
            diskSpoolBufferSizeMB="30"
            diskPersistent="false"
            diskExpiryThreadIntervalSeconds="120"
            memoryStoreEvictionPolicy="LRU"
            statistics="false"
            />

    <cache name="PageCacheFilter"
           maxElementsInMemory="1000"
           maxElementsOnDisk="10000"
           eternal="false"
           overflowToDisk="true"
           diskSpoolBufferSizeMB="20"
           timeToIdleSeconds="300"
           timeToLiveSeconds="600"
           memoryStoreEvictionPolicy="LFU"
           transactionalMode="off"
            />


</ehcache>

 麻烦大神们看看哪里有问题?

 

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • jinnianshilongnian 2013-04-15 12:18
    已采纳

    Element does not allow nested elements.

    你把这个删掉试试

    或者下载我之前集成好的 拷贝过去用
    [url]http://jinnianshilongnian.iteye.com/blog/1423971[/url]

    点赞 评论
  • zyn010101 2013-04-15 12:44

    所有的ehcach版本不支持transactionManagerLookup 节点属性,建议去官网下载,利用里面的jar包和xml配置文件,再对xml进行修改

    点赞 评论
  • hejiaqi789 2013-04-15 13:34

    根据你的错误提示
    请去除 defaultCache 里面的 maxElementsOnDisk="10000" 试一下.

    点赞 评论

相关推荐 更多相似问题