我想使用Spring Data Populator,但我得到SAXParseException
:
Exception in thread "main"
org.springframework.beans.factory.parsing.BeanDefinitionParsingException:
Configuration problem: Failed to import bean definitions from URL location
[classpath*:spring-context/dbContext.xml]
Offending resource: class path resource [spring-context/applicationContext.xml];
nested exception is org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException:
Line 64 in XML document from URL [file:/home/pi/Workspace/AGServer/bin/spring-context/dbContext.xml] is invalid;
nested exception is org.xml.sax.SAXParseException: cvc-complex-type.3.2.2:
Attribute 'location' is not allowed to appear in element 'repository:jackson-populator'.
我的主要服务器类是:
public final class ServerMain {
private static final String APP_CONTEXT_XML = "spring-context/applicationContext.xml";
public static void main(final String[] args) {
final ConfigurableApplicationContext context = new ClassPathXmlApplicationContext(APP_CONTEXT_XML);
context.registerShutdownHook();
}
}
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"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<import resource="classpath*:spring-context/serverContext.xml" />
<import resource="classpath*:spring-context/dbContext.xml" />
<import resource="classpath*:spring-context/jettyContext.xml" />
</beans>
最后,我调用Populator的dbContext.xml的开头
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:repository="http://www.springframework.org/schema/data/repository"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
http://www.springframework.org/schema/data/repository http://www.springframework.org/schema/data/repository/spring-repository.xsd">
<!-- AUTH DS / PU / TX / SERVICE -->
<!-- the repositories configuration, ommited for clarity -->
<repository:jackson-populator location="classpath:auth.json" />
可能是由于与spring-beans-3.0.xsd的冲突造成的?我在所有(虽然不是太多,例如这里:http://docs.spring.io/spring-data/commons/docs/1.5.1.RELEASE/reference/htmlsingle/???#d0e893)文件中看到spring-beans.xsd,没有任何版本ID被使用。我试图改变它,但那没有用。