<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=javapro123" rel="nofollow">Ashish</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-8850?redirect=false" rel="nofollow">SPR-8850</a></strong> and commented</p>
<p dir="auto">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</p>
<p dir="auto">&lt;cache:annotation-driven key-generator="myKeyGenerator"/&gt;</p>
<p dir="auto">Error:</p>
<hr>
<p dir="auto">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'.<br>
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:396)<br>
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)<br>
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)<br>
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)<br>
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)<br>
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)<br>
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:243)<br>
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:127)<br>
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:94)<br>
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:131)<br>
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:523)<br>
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:436)<br>
at org.springframework.context.support.ClassPathXmlApplicationContext.&lt;init&gt;(ClassPathXmlApplicationContext.java:139)<br>
at org.springframework.context.support.ClassPathXmlApplicationContext.&lt;init&gt;(ClassPathXmlApplicationContext.java:84)<br>
at com.iw.cache.CacheTest.main(CacheTest.java:10)<br>
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'.<br>
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)<br>
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:131)<br>
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:384)<br>
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:318)<br>
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator$XSIErrorReporter.reportError(XMLSchemaValidator.java:417)<br>
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.reportSchemaError(XMLSchemaValidator.java:3182)<br>
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.processAttributes(XMLSchemaValidator.java:2659)<br>
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:2066)<br>
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.emptyElement(XMLSchemaValidator.java:725)<br>
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:377)<br>
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2755)<br>
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)<br>
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)<br>
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)<br>
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)<br>
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)<br>
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)<br>
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:235)<br>
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:284)<br>
at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:75)<br>
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:388)<br>
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)<br>
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)<br>
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)<br>
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)<br>
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)<br>
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:243)<br>
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:127)<br>
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:93)<br>
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:131)<br>
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:522)<br>
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:436)<br>
at org.springframework.context.support.ClassPathXmlApplicationContext.&lt;init&gt;(ClassPathXmlApplicationContext.java:139)<br>
at org.springframework.context.support.ClassPathXmlApplicationContext.&lt;init&gt;(ClassPathXmlApplicationContext.java:83)<br>
... 1 more</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 3.1 RC1</p>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=headset" rel="nofollow">ML</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-2664?redirect=false" rel="nofollow">SPR-2664</a></strong> and commented</p>
<p dir="auto">Section 9.3 in the manual states:</p>
<p dir="auto">"If we use JTA, as in the dataAccessContext-jta.xml file from the same sample application, we need to use a container DataSource, obtained via JNDI, and a JtaTransactionManager implementation."</p>
<p dir="auto">But <a href="http://www.onjava.com/lpt/a/6469" rel="nofollow">http://www.onjava.com/lpt/a/6469</a> appears to show JTA without JNDI and without an app server:</p>
<p dir="auto">"In our scenario, we will process incoming bank orders from a Java Message Service (JMS) queue. The processing of an order involves updating the account database via Java Database Connectivity (JDBC). In order to avoid message loss or duplicates, we will use the Java Transaction API (JTA) and JTA/XA transactions to coordinate the updates: consuming a message and updating the database will happen in one atomic transaction."</p>
<p dir="auto">"If we were using an application server, then we would have to resort to Java Naming and Directory Interface (JNDI) lookups instead."</p>
<p dir="auto">unrelated side note: I keep reading how JMS also requires an app server and here it looks like that's not really the case.  Comments, corrections, clarifications on this would be most welcome.</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 2.0 RC4</p>