本文介绍了问题与应用程序内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



 <$ c我开发了一个应用程序,使用spring和hibernate,所以我在应用程序内容文件中遇到问题。 $ c>< beans xmlns =http://www.springframework.org/schema/beans

xmlns:xsi =http://www.w3.org/2001/XMLSchema-实例

xsi:schemaLocation =http://www.springframework.org/schema/beans


http://www.springframework.org/模式/豆类/弹簧豆-3.0.xsd>

< import resource =../ database / dataSource.xml/>
< import resource =../ database / hibernate.cfg.xml/>

< import resource =../ beans / databeans.xml/>
< / beans>

我的问题是:



 线程main中的异常java.lang.ExceptionInInitializerError $ b $ com com.mass.masster.data.utils.InputData。< init>(InputData.java:40)
at com.mass.masster.data.utils.InputData.main(InputData.java:303)
导致:org.springframework.beans.factory.BeanDefinitionStoreException:来自类路径资源的XML文档中的第4行[spring / config /application.context.xml]无效;嵌套的异常是org.xml.sax.SAXParseException:L'élémentracine de documentbeansdoit correspondreàla racine DOCTYPEnull。
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:133)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:125)$ b在org.springframework.context.support.AbstractXmlApplicationContext.refreshBeanFactory(AbstractXmlApplicationContext.java:65)
$ b在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:226)
。在组织.springframework.context.support.ClassPathXmlApplicationContext<初始化>(ClassPathXmlApplicationContext.java:58)在com.mass.masster.core.utils.BeanFactory
将。clinit>(BeanFactory.java:35)
... 2 more
导致:org.xml.sax.SAXParseException; lineNumber:4; columnNumber:132; *** L'élémentracine de documentbeansdoit correspondreàla racine DOCTYPEnull。***
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source )
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(未知源)
在com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(未知源)
在com.sun.org.apache.xerces.internal.impl.XMLErrorReporter。 reportError(未知源)
在com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.rootElementSpecified(未知源)
在com.sun.org.apache.xerces.internal。 impl.dtd.XMLDTDValidator.handleStartElement(来源不明)在com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.startElement
(来源不明)
。在com.sun.org。 apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStart Element(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl $ ContentDriver.scanRootElementHook(Unknown Source)
at com.sun.org.apache.xerces.internal。 impl.XMLDocumentFragmentScannerImpl $ FragmentContentDriver.next(来源不明)在com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl $ PrologDriver.next(来源不明)在com.sun.org

。 apache.xerces.internal.impl.XMLDocumentScannerImpl.next(来源不明)在com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument
(来源不明)
在的com.sun。 org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com。 sun.org.apache.xerces.internal.parsers.XMLParser.parse(未知来源)
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(未知来源)
at com.sun.org.apache.xerces.inte rnal.jaxp.DocumentBuilderImpl.parse(来源不明)在javax.xml.parsers.DocumentBuilder.parse
(来源不明)
在org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader。 java:126)
... 7 more

hibernate.cfg.xml

 <?xml version =1.0encoding =UTF-8?> 
< beans xmlns =http://www.springframework.org/schema/beans
xmlns:xsi =http://www.w3.org/2001/XMLSchema-instancexmlns :tx =http://www.springframework.org/schema/tx
xmlns:context =http://www.springframework.org/schema/context
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.xsd\">


< bean id =sessionFactory
class =org.springframework.orm.hibernate3.LocalSessionFactoryBean>

< property name =dataSource>
< ref bean =dataSource/>
< / property>

< property name =hibernateProperties>
<道具>
< prop key =hibernate.dialect> org.hibernate.dialect.MySQLDialect< / prop>
< prop key =hibernate.show_sql> true< / prop>
< prop key =hibernate.hbm2ddl.auto> update< / prop>
< prop key =bonecp.idleMaxAge> 240< / prop>
< prop key =bonecp.idleConnectionTestPeriod> 60< / prop>
< prop key =bonecp.partitionCount> 3< / prop>
< prop key =bonecp.acquireIncrement> 10< / prop>
< prop key =bonecp.maxConnectionsPerPartition> 60< / prop>
< prop key =bonecp.minConnectionsPerPartition> 20< / prop>
< prop key =bonecp.statementsCacheSize> 50< / prop>
< prop key =bonecp.releaseHelperThreads> 3< / prop>
< /道具>
< / property>

< property name =mappingLocations>
< list>
< value> classpath:/ hibernate / model / **。hbm.xml< / value>
< / list>
< / property>

< / bean>

< tx:annotation-driven transaction-manager =txManager/>

< bean id =txManager
class =org.springframework.orm.hibernate3.HibernateTransactionManager>
< property name =sessionFactoryref =sessionFactory/>
< / bean>

< / beans>

datasource.xml

 < beans xmlns =http://www.springframework.org/schema/beans
xmlns:xsi =http://www.w3。 org / 2001 / XMLSchema-instance
xsi:schemaLocation =http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-豆-2.5.xsd>

< bean
class =org.springframework.beans.factory.config.PropertyPlaceholderConfigurer>
< property name =location>
< value> properties / database.properties< / value>
< / property>
< / bean>

< bean id =dataSource
class =org.springframework.jdbc.datasource.DriverManagerDataSource>
< property name =driverClassNamevalue =$ {jdbc.driverClassName}/>
< property name =urlvalue =$ {jdbc.url}/>
< property name =usernamevalue =$ {jdbc.username}/>
< property name =passwordvalue =$ {jdbc.password}/>
< / bean>

< / beans>


解决方案

配置文件存在问题。这个错误很明显,它说XML解析器不能解析文件。在eclipse中打开文件,并右键单击并选择验证xml选项并修复问题。



希望这有帮助!


I'm developing an application with spring and hibernate so I'm facing a problem with my application content file here my code:

 <beans xmlns="http://www.springframework.org/schema/beans"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://www.springframework.org/schema/beans


    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

<!-- Database Configuration -->
<import resource="../database/dataSource.xml" />
<import resource="../database/hibernate.cfg.xml" />

<!-- Beans Declaration -->
 <import resource="../beans/databeans.xml" />
    </beans>

my problem is:

Exception in thread "main" java.lang.ExceptionInInitializerError
    at com.mass.masster.data.utils.InputData.<init>(InputData.java:40)
    at com.mass.masster.data.utils.InputData.main(InputData.java:303)
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Line 4 in XML document from class path resource [spring/config/application.context.xml] is invalid; nested exception is org.xml.sax.SAXParseException: L'élément racine de document "beans" doit correspondre à la racine DOCTYPE "null".
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:133)
    at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:125)
    at org.springframework.context.support.AbstractXmlApplicationContext.refreshBeanFactory(AbstractXmlApplicationContext.java:65)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:226)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:58)
    at com.mass.masster.core.utils.BeanFactory.<clinit>(BeanFactory.java:35)
    ... 2 more
Caused by: org.xml.sax.SAXParseException; lineNumber: 4; columnNumber: 132; ***L'élément racine de document "beans" doit correspondre à la racine DOCTYPE "null".***
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.rootElementSpecified(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleStartElement(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.startElement(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$ContentDriver.scanRootElementHook(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
    at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:126)
    ... 7 more

hibernate.cfg.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:tx="http://www.springframework.org/schema/tx"
    xmlns:context="http://www.springframework.org/schema/context"
    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.xsd">


    <!-- Hibernate session factory -->
    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" >

        <property name="dataSource">
            <ref bean="dataSource" />
        </property>

        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.hbm2ddl.auto">update</prop>
                <prop key="bonecp.idleMaxAge">240</prop>
                <prop key="bonecp.idleConnectionTestPeriod">60</prop>
                <prop key="bonecp.partitionCount">3</prop>
                <prop key="bonecp.acquireIncrement">10</prop>
                <prop key="bonecp.maxConnectionsPerPartition">60</prop>
                <prop key="bonecp.minConnectionsPerPartition">20</prop>
                <prop key="bonecp.statementsCacheSize">50</prop>
                <prop key="bonecp.releaseHelperThreads">3</prop>
            </props>
        </property>

        <property name="mappingLocations">
            <list>
                <value>classpath:/hibernate/model/**.hbm.xml</value>
            </list>
        </property>

    </bean>

    <tx:annotation-driven transaction-manager="txManager" />

    <bean id="txManager"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>

</beans>

datasource.xml

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

    <bean
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location">
            <value>properties/database.properties</value>
        </property>
    </bean>

    <bean id="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="${jdbc.driverClassName}" />
        <property name="url" value="${jdbc.url}" />
        <property name="username" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />
    </bean>

</beans>
解决方案

There is a problem in your configuration file. The error is obvious and it says XML parser is not able to parse the file. Open the file in eclipse , and right click and choose "validate xml" option and fix the issue.

Hope this is helpful!

这篇关于问题与应用程序内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-27 21:50
查看更多