Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring 3.1 RC1 includes stale duplicate of spring-cache XSD [SPR-8850] #13492

Closed
spring-projects-issues opened this issue Nov 14, 2011 · 8 comments
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Nov 14, 2011

Ashish opened SPR-8850 and commented

I am trying to specify a custom key generator. When I have the following in the config file for enabling annotation based caching I get the error while loading the config file. I need to generate a hashCode based on the combination of methodName + params

<cache:annotation-driven key-generator="myKeyGenerator"/>

Error:


Exception in thread "Main Thread" org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 10 in XML document from class path resource [MyContext.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-complex-type.3.2.2: Attribute 'key-generator' is not allowed to appear in element 'cache:annotation-driven'.
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:396)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:243)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:127)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:94)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:131)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:523)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:436)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:84)
at com.iw.cache.CacheTest.main(CacheTest.java:10)
Caused by: org.xml.sax.SAXParseException: cvc-complex-type.3.2.2: Attribute 'key-generator' is not allowed to appear in element 'cache:annotation-driven'.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:131)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:384)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:318)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator$XSIErrorReporter.reportError(XMLSchemaValidator.java:417)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.reportSchemaError(XMLSchemaValidator.java:3182)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.processAttributes(XMLSchemaValidator.java:2659)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:2066)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.emptyElement(XMLSchemaValidator.java:725)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:377)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2755)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:235)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:284)
at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:75)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:388)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:243)
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:131)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:522)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:436)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
... 1 more


Affects: 3.1 RC1

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Nov 14, 2011

Ashish commented

This is a standalone app and the entire config file is like this:

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cache="http://www.springframework.org/schema/cache"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/cache
http://www.springframework.org/schema/cache/spring-cache-3.1.xsd">

<cache:annotation-driven key-generator="myKeyGenerator"/> 

<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager"
	p:cache-manager-ref="ehcache" />
<bean id="ehcache"
	class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"
	p:config-location="classpath:ehcache.xml" />
	
	<bean id="myCacheService"
				class="com.iw.cache.MyCacheService"
	/>
	

	<bean id="myKeyGenerator"
		class="com.iw.cache.MyKeyGenerator" />

</beans>

@spring-projects-issues
Copy link
Collaborator Author

Chris Beams commented

Hi Ashish,

Looking over your report, it's unclear why you would be getting such an exception. The key-generator attribute name is correct and supported. You'll see it in the XSD. There are test cases within the framework that prove this.

If this issue persists for you, please consider submitting a simple reproduction project per these instructions: https://github.com/SpringSource/spring-framework-issues#readme

Otherwise, this issue will be closed as 'cannot reproduce'.

Thanks!

@spring-projects-issues
Copy link
Collaborator Author

Ashish commented

Hi Chris,

Please take a look at the xsd bundled with the
jar file at org.springframework.context.support-3.1.0.RC1.jar\org\springframework\cache\config\

There is no key-generator mentioned there. That's why it fails. The test cases in the framework may be reading the xsd from http://www.springframework.org/schema/cache/spring-cache-3.1.xsd and that one is correct but not the one in the jar file that get downloaded with the spring 3.1 framework. I was able to make it work once I deleted the xsd from the springframework jar.

Thanks,
Ashish

@spring-projects-issues
Copy link
Collaborator Author

Chris Beams commented

Ashish,

Sorry for the confusion. The spring-cache XSD was originally developed within the .context.support module, but now lives in .context. The old version was accidentally not removed and RC1 was pushed out with both versions. The older version does not have the key-generator attribute. Your issue is likely due to the fact that the spring-context-support jar has precedence on your classpath over the spring-context jar.

There are two workarounds for this problem:

  1. upgrade to nightly snapshots. I actually removed the duplicate copy just yesterday, and so there is a snapshot available with this fix already.
  2. reverse the classpath precedence of spring-context and spring-context-support. Give spring-context precedence and the "right" spring-cache XSD will kick in.

@spring-projects-issues
Copy link
Collaborator Author

Chris Beams commented

Already fixed with the following commit:

commit 2b4679d7707ef27101942a62575079cd27dd18fe
Author: Chris Beams <cbeams@vmware.com>
Date:   Wed Nov 16 04:20:43 2011 +0000

    Remove stale duplicate copy of spring-cache XSD
    
    This was removed once previously but accidentally re-introduced later.
    The 'correct' version of spring-cache-3.1.xsd lives in spring-context
    as opposed to here in spring-context-support.
    
    Also placed .gitignore file within src/main/resources such that the
    now-empty directory does not get pruned in git environments, which will
    otherwise cause 'missing source folder' errors within Eclipse/IDEA.

@spring-projects-issues
Copy link
Collaborator Author

Ashish commented

Chris,

I checked both xsd's, the one in .context and the one in .context.support and both had the entry missing. I am glad its fixed.

Ashish

@spring-projects-issues
Copy link
Collaborator Author

Chris Beams commented

Take a look here:

http://repo.springsource.org/libs-milestone-s3-cache/org/springframework/spring-context/3.1.0.RC1/spring-context-3.1.0.RC1.jar!/org/springframework/cache/config/spring-cache-3.1.xsd

This is the spring-context jar as released for 3.1.0.RC1, and the spring-context XSD within does in fact contain the key-generator attribute.

@spring-projects-issues
Copy link
Collaborator Author

Ashish commented

ok.
Thanks.

@spring-projects-issues spring-projects-issues added type: bug A general bug in: core Issues in core modules (aop, beans, core, context, expression) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 3.1 RC2 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

1 participant