Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 找不到元素';ehcache';_Java_Spring_Ehcache - Fatal编程技术网

Java 找不到元素';ehcache';

Java 找不到元素';ehcache';,java,spring,ehcache,Java,Spring,Ehcache,我正在我的web应用程序中实现url缓存。运行时,我在ehcache.xml文件中出错。我使用的是Spring2.5JAR文件 ehcache.xml <?xml version="1.0" encoding="UTF-8"?> <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="f

我正在我的web应用程序中实现url缓存。运行时,我在ehcache.xml文件中出错。我使用的是Spring2.5JAR文件

ehcache.xml

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

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


    <defaultCache eternal="false" maxElementsInMemory="1000"
        overflowToDisk="false" diskPersistent="false" timeToIdleSeconds="0"
        timeToLiveSeconds="600" memoryStoreEvictionPolicy="LRU" />

    <cache name="videoItemsCache" eternal="false"
        maxElementsInMemory="1000" timeToIdleSeconds="1200" timeToLiveSeconds="1200"
        overflowToDisk="false" diskPersistent="false"
        memoryStoreEvictionPolicy="LRU" />

</ehcache>

请任何人帮助我。

试试这样的东西,我正在我的项目中使用这个

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:ehcache="http://www.springmodules.org/schema/ehcache"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springmodules.org/schema/ehcache http://www.springmodules.org/schema/cache/springmodules-ehcache.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">

    <ehcache:config configLocation="classpath:ehcache.xml" />

    <ehcache:proxy id="saleDAO" refId="saleDAOTarget">
        <ehcache:caching cacheName="saleCache" methodName="findAll"/>
        <ehcache:flushing cacheNames="saleCache" methodName="saveSaleRecord" when="after"/>
    </ehcache:proxy>

    <bean id="saleDAOTarget" class="byteco.de.spring.SaleDAOImpl">
        <property name="namedParameterJdbcTemplate" ref="jdbcTemplate"></property>
    </bean>

    <bean id="datasource" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
        <property name="username" value="root"/>
        <property name="password" value="password"/>
        <property name="initialSize" value="5"/>
        <property name="url" value="jdbc:mysql://localhost:3306/demo"/>
    </bean>

    <bean id="jdbcTemplate" class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate">
        <constructor-arg type="javax.sql.DataSource" ref="datasource"/>
    </bean>
</beans>
<ehcache>
    <defaultCache
            maxElementsInMemory="500" eternal="true" overflowToDisk="false" memoryStoreEvictionPolicy="LFU"/>
    <cache name="contactCache" maxElementsInMemory="500" eternal="true" overflowToDisk="false"
           memoryStoreEvictionPolicy="LFU"/>
</ehcache>

ehcache.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:ehcache="http://www.springmodules.org/schema/ehcache"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springmodules.org/schema/ehcache http://www.springmodules.org/schema/cache/springmodules-ehcache.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">

    <ehcache:config configLocation="classpath:ehcache.xml" />

    <ehcache:proxy id="saleDAO" refId="saleDAOTarget">
        <ehcache:caching cacheName="saleCache" methodName="findAll"/>
        <ehcache:flushing cacheNames="saleCache" methodName="saveSaleRecord" when="after"/>
    </ehcache:proxy>

    <bean id="saleDAOTarget" class="byteco.de.spring.SaleDAOImpl">
        <property name="namedParameterJdbcTemplate" ref="jdbcTemplate"></property>
    </bean>

    <bean id="datasource" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
        <property name="username" value="root"/>
        <property name="password" value="password"/>
        <property name="initialSize" value="5"/>
        <property name="url" value="jdbc:mysql://localhost:3306/demo"/>
    </bean>

    <bean id="jdbcTemplate" class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate">
        <constructor-arg type="javax.sql.DataSource" ref="datasource"/>
    </bean>
</beans>
<ehcache>
    <defaultCache
            maxElementsInMemory="500" eternal="true" overflowToDisk="false" memoryStoreEvictionPolicy="LFU"/>
    <cache name="contactCache" maxElementsInMemory="500" eternal="true" overflowToDisk="false"
           memoryStoreEvictionPolicy="LFU"/>
</ehcache>

xsi:noNamespaceSchemaLocation=“ehcache.xsd”

此位置必须是绝对路径

如下所示:…Location=“classpath:/yourPathInProject/ehcache.xml”

在此之前,您需要从下载ehcache.xml
并将其放在您的路径中。

对于ehcache 3.x,您可以参考以下ehcache.xml模板:

    <config
    xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
    xmlns='http://www.ehcache.org/v3'
    xsi:schemaLocation="
        http://www.ehcache.org/v3 http://www.ehcache.org/schema/ehcache-core-3.0.xsd">

  <cache alias="ready-cache">
    <key-type>java.lang.Long</key-type>
    <value-type>com.pany.domain.Product</value-type>
    <loader-writer>
      <class>com.pany.ehcache.integration.ProductCacheLoaderWriter</class>
    </loader-writer>
    <heap unit="entries">100</heap>
  </cache>

</config>

java.lang.Long
com.pany.domain.Product
com.pany.ehcache.integration.ProductCacheLoaderWriter
100
基本上,对ehcache的xsd的引用是根据上述xsd声明更新的。
有关如何为ehcache 3.x使用不同XML选项的更多详细信息,请参阅

请添加spring配置,并检查类路径中的echache.XML。如果您使用web应用程序,请确保可以在web-INF/classes中找到echache.xml,并且此答案将在脱机环境中运行ehcache