使用 XML 配置在 Ehcache3.8.1 中获取重复的身份约束名称

问题描述

我遇到了带有 XML 配置文件的 ehcache 3.8.1 异常(该应用程序是部署到 weblogic 服务器的 EAR)。有没有人遇到过这个问题?当调试 ehcache 中的代码时,我发现在下面的代码中得到三个 XML 模式,它被 ConfigurationParser.java 剪断了,并且重复失败了。我做错了吗?

 public static Schema discoverSchema(Source ... fixedSources) throws SAXException,IOException {
    ArrayList<Source> schemaSources = new ArrayList<>(asList(fixedSources));
    for (CacheManagerServiceConfigurationParser<?> p : servicesOfType(CacheManagerServiceConfigurationParser.class)) {
      schemaSources.add(p.getXmlSchema());
    }
    for (CacheServiceConfigurationParser<?> p : servicesOfType(CacheServiceConfigurationParser.class)) {
      schemaSources.add(p.getXmlSchema());
    }
    for (CacheResourceConfigurationParser p : servicesOfType(CacheResourceConfigurationParser.class)) {
      schemaSources.add(p.getXmlSchema());
    }
    return newSchema(schemaSources.toArray(new Source[0]));
  }

出现以下异常

Error on line 28
  Duplicate identity constraint name {default-template-ref} - prevIoUsly defined on line 28 of
Error on line 37
  Duplicate identity constraint name {template-ref} - prevIoUsly defined on line 37 of
org.ehcache.xml.exceptions.XmlConfigurationException: Error parsing XML configuration at file:/D:/*********/UIM/config/ehcache3.xml
        at org.ehcache.xml.XmlConfiguration.<init>(XmlConfiguration.java:124) ~[ehcache-3.8.1.jar:3.8.1 a19322e8d4b3f7157e878112c2afc0b6e3090fdd]
        at org.ehcache.xml.XmlConfiguration.<init>(XmlConfiguration.java:90) ~[ehcache-3.8.1.jar:3.8.1 a19322e8d4b3f7157e878112c2afc0b6e3090fdd]

代码如下:

URL url = getClass().getResource("/"+configFileName);
Configuration xmlConfig = new XmlConfiguration(url);
admin = CacheManagerBuilder.newCacheManager(xmlConfig);
admin.init();

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.xsd">
            
  <cache-template name="myDefaults"> 
    <key-type>java.lang.String</key-type>
    <value-type>java.lang.Object</value-type>
    <heap unit="entries">1000</heap>
  </cache-template>
  
  <cache alias="cache3" uses-template="myDefaults" />

  </config>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...