2014-03-06 52 views
0

發現我有使用彈簧的Ehcache的應用程序。 EAch時間,我從Eclipse啓動應用程序,它運行良好。但是,當我從Maven構建,並在服務器上運行它,我一直有這個錯誤:ehcache的彈簧,1.2.xsd存在「的Ehcache:註解驅動」的定義不能在我的Spring上下文文件

INFO XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [spring.xml] 
    Exception in thread "main"  org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 29 in XML document from class path 
resource [spring.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 29; columnNumber: 71; cvc-complex-type.2. 
4.c: The matching wildcard is strict, but no declaration can be found for element 'ehcache:annotation-driven'. 
     at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:398) 
     at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:335) 
     at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:303) 
     at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180) 
     at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:216) 
     at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:187) 
     at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:251) 
     at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:127) 
     at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:93) 
     at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129) 
     at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:540) 
     at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:454) 
     at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139) 
     at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93) 
     at com.natixis.etp.data.rmi.DataServer.main_aroundBody0(DataServer.java:145) 
     at com.natixis.etp.data.rmi.DataServer.main(DataServer.java:45) 
Caused by: org.xml.sax.SAXParseException; lineNumber: 29; columnNumber: 71; cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'ehcache:annotation-driven'. 
     at org.apache.xerces.parsers.DOMParser.parse(Unknown Source) 
     at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source) 
     at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:76) 
     at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadDocument(XmlBeanDefinitionReader.java:428) 
     at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390) 

ehcache:annotation-driven定義。
我看了一下它的幾個相關問題,我申請什麼勸,到目前爲止,我沒有運氣。我沒有,也不能使用Maven的着色器插件,因爲我們的環境細節,我不認爲這會有所幫助,因爲我檢查並重新檢查了依賴關係中的模式處理程序。

之前,我殺了我自己,我想知道,如果您有任何線索。這裏是我的春天文件:

 <?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:context="http://www.springframework.org/schema/context" 
      xmlns:tx="http://www.springframework.org/schema/tx" 
      xmlns:aop="http://www.springframework.org/schema/aop" 
      xmlns:ehcache="http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring" 
      xsi:schemaLocation=" 
      http://www.springframework.org/schema/beans 
      http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
      classpath:spring-beans-3.0.xsd 
      http://www.springframework.org/schema/aop 
      http://www.springframework.org/schema/aop/spring-aop-3.0.xsd 
      classpath:spring-aop-3.0.xsd 
      http://www.springframework.org/schema/context 
      http://www.springframework.org/schema/context/spring-context-3.2.xsd 
      classpath:spring-context.xsd 
      http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring 
      http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.2.xsd 
      classpath:ehcache-spring-1.2.xsd 
      "> 

      <context:annotation-config /> 
      <context:spring-configured /> 

      [...] 

      <ehcache:annotation-driven mode="aspectj" 
       cache-manager="cacheManager" self-populating-cache-scope="shared" /> 

      <aop:aspectj-autoproxy> 
       <aop:include name="traceInvocation" /> 
       <!-- aop:include name="performanceMonitor"/--> 
       <aop:include name="ehCacheInvocation" /> 
      </aop:aspectj-autoproxy> 

      <ehcache:config cache-manager="cacheManager"> 
       <ehcache:evict-expired-elements 
        interval="60" /> 
      </ehcache:config> 

      <bean id="cacheManager" 
       class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"> 
       <property name="configLocation" value="META-INF/ehcache.xml" /> 
       <property name="shared" value="true" /> 
      </bean> 
      [...] 
     </beans> 

正如你看到的,我添加了類路徑條目,因爲我已經使用Spring AOP架構處理器中的架構處理衝突。 我已經檢查的ehcache-aspectj-annotations-1.2.0.jar.dir/META-INF/spring.schemas內容:

http\://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.0.xsd=com/googlecode/ehcache/annotations/ehcache-spring-1.0.xsd 
http\://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.1.xsd=com/googlecode/ehcache/annotations/ehcache-spring-1.1.xsd 
http\://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.2.xsd=com/googlecode/ehcache/annotations/ehcache-spring-1.2.xsd 

這似乎沒什麼問題。

任何幫助將不勝感激。 乾杯。

編輯:

這裏是我的方式主要依賴:

<dependencies> 
    [...] 
     <dependency> 
      <groupId>aopalliance</groupId> 
      <artifactId>aopalliance</artifactId> 
      <version>1.0</version> 
     </dependency> 
     <dependency> 
      <groupId>xerces</groupId> 
      <artifactId>xercesImpl</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-beans</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-core</artifactId> 
      <scope>compile</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-context</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-context-support</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>net.sf.ehcache</groupId> 
      <artifactId>ehcache-core</artifactId> 
      <version>2.4.1</version> 
      <scope>compile</scope> 
     </dependency> 
     <dependency> 
      <groupId>**************</groupId> 
      <artifactId>ehcache-aspectj-annotations</artifactId> 
      <version>1.2.0</version> 
      <scope>compile</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.aspectj</groupId> 
      <artifactId>aspectjrt</artifactId> 
      <version>${aspectj.version}</version> 
      <scope>compile</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.aspectj</groupId> 
      <artifactId>aspectjweaver</artifactId> 
      <version>${aspectj.version}</version> 
     </dependency> 

     <dependency> 
      <groupId>com.googlecode.ehcache-spring-annotations</groupId> 
      <artifactId>ehcache-spring-annotations</artifactId> 
      <version>1.2.0</version> 
     </dependency> 
    </dependencies> 
+0

你有沒有添加的依賴關係的Ehcache的註解在Maven POM或在Eclipse?它需要是一個maven的依賴 –

+0

是的肖恩。我通過使其更清晰的方式添加了我的依賴關係。其實,我的依賴項中有「ehcache-aspectj-annotations」,我沒有「ehcache-annotations」,我會檢查它。 – user3206745

+0

肖恩,我添加了以下的依賴,這似乎是必需的,但沒有成功: com.googlecode.ehcache彈簧的註解 的Ehcache彈簧的註解 1.2.0 user3206745

回答

0

好吧,我一直沒能找到問題的根本原因,但我試圖用Spring bean源代碼,以便跟蹤導致此問題的調用。 看來,我使用的Spring bean版本(4.0.2-RELEASE)引用了Java 8類,儘管我的項目是在Java 7下。

我不確定是否因爲我期望它是問題一個明確的錯誤信息,但無論如何,我回滾到Java 7兼容版本的spring beans(3.2.8.RELEASE),問題就消失了。它現在工作正常,即使它有點令人沮喪。

0

我也有類似的問題,想增加一些細節,以防他人在搜索。錯誤:

nested exception is org.xml.sax.SAXParseException; lineNumber: 29; columnNumber: 71; cvc-complex-type.2. 4.c: The matching wildcard is strict, but no declaration can be found for element 'ehcache:annotation-driven'.

意味着它不能找到什麼ehcache:annotation-driven手段。這是因爲uri上的xsd文件不再被託管。我找到了該文件的存檔版本,並將其放在同一目錄中,然後可以通過相對路徑引用xsd。

有關更多詳細信息,請參閱相關問題和答案:How to Configure Eclipse to Work with `ehcache`How to Reference Local XSD File By Relative PathContext.xml's References

相關問題