0

试图读取这个 persistence.xml 文件:

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
             http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
             version="2.1">
    <persistence-unit name="Eclipselink_JPA" transaction-type="RESOURCE_LOCAL">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <exclude-unlisted-classes>false</exclude-unlisted-classes>
        <properties>
            <property name="javax.persistence.jdbc.db" value="polldb"/>
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/polldb"/>
            <property name="javax.persistence.jdbc.user" value="root"/>
            <property name="javax.persistence.jdbc.password" value=""/>
            <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
            <property name="javax.persistence.schema-generation.database.action" value="create"/>
        </properties>
    </persistence-unit>
</persistence>

使用:

                Properties props = new Properties();
                props.loadFromXML(this.getClass().getResourceAsStream("/META-INF/persistence.xml"));

它返回此错误: Caused by: org.xml.sax.SAXParseException; lineNumber: 6; columnNumber: 28; Document root element "persistence", must match DOCTYPE root "null".

有人知道它可能是什么吗?太感谢了!!

4

0 回答 0