类路径资源中的XML文档

时间:2013-04-17 00:42:53

标签: spring-jdbc

我收到此错误。我正在关注一个在线示例。它运行正常,直到我添加Spring.xml以从xml文件获取jdbc登录值。

我的XML文件位于src文件夹

主要代码:

ApplicationContext ctx = new ClassPathXmlApplicationContext("spring.xml");, 
JdbcImpl daoImpl = ctx.getBean("jdbcImpl", JdbcImpl.class);, 
IdpTpgInputFile idpInputFile = daoImpl.getInputFile(1);, 
System.out.println(idpInputFile.getFileName());

错误:

Apr 16, 2013 5:24:36 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@b61d36b:
    startup date [Tue Apr 16 17:24:36 PDT 2013];
    root of context hierarchy
Apr 16, 2013 5:24:36 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [spring.xml]
    Exception in thread "main" org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: 
    Line 18 in XML document from class path resource [spring.xml] is invalid;
    nested exception is org.xml.sax.SAXParseException:
        Open quote is expected for attribute "{1}" associated with an  element type  "name".
        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:143),
        at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178),
        at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149),
        at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:212)
        ,at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:126),
        at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:92),
        at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130),
        at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:467),
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:397),
        at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139),
        at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83),
        at com.amar.jdbc.JdbcMain.main(JdbcMain.java:21)

2 个答案:

答案 0 :(得分:2)

看起来你错过了ApplicationContext.xml文件中的以下语句。检查一次。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

答案 1 :(得分:0)

原因是spring.xml中第18行缺少元素类型“name”的开放引号。请检查。祝你好运:)