Hibernate反向建立hbm和dao,po时 Document is invalid: no grammar found

J2EE 码拜 9年前 (2015-08-12) 1551次浏览

使用MyEclipse10.7整合Struts2.1+Spring3.0+Hibernate3.3。

在DB Borwser透视图中,Hibernate Reverse Engineering向导进行表的映射和DAO自动生成时

 

控制台显示如下错误,请问怎么解决

2015-08-07 17:42:58,091 ERROR Worker-13 org.hibernate.util.XMLHelper – Error parsing XML: D:\Workspaces\PokeManagerSystem\WebRoot\WEB-INF\applicationContext.xml(3) Document is invalid: no grammar found.
2015-08-07 17:42:58,091 ERROR Worker-13 org.hibernate.util.XMLHelper – Error parsing XML: D:\Workspaces\PokeManagerSystem\WebRoot\WEB-INF\applicationContext.xml(3) Document root element “beans”, must match DOCTYPE root “null”.

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:p="http://www.springframework.org/schema/p"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">


	<bean id="dataSource"
		class="org.apache.commons.dbcp.BasicDataSource">
		<property name="driverClassName"
			value="com.mysql.jdbc.Driver">
		</property>
		<property name="url"
			value="jdbc:mysql://localhost:3306/Pokemon">
		</property>
		<property name="username" value="root"></property>
		<property name="password" value="laomin"></property>
	</bean>
	<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>
			</props>
		</property>
		<property name="mappingResources">
			<list>
				<value>com/poke/po/Manager.hbm.xml</value>
				<value>com/poke/po/Player.hbm.xml</value>
				<value>com/poke/po/Asd.hbm.xml</value></list>
		</property></bean>
	<bean id="ManagerDAO" class="com.poke.po.ManagerDAO">
		<property name="sessionFactory">
			<ref bean="sessionFactory" />
		</property>
	</bean>
	<bean id="PlayerDAO" class="com.poke.po.PlayerDAO">
		<property name="sessionFactory">
			<ref bean="sessionFactory" />
		</property>
	</bean>
	<bean id="AsdDAO" class="com.poke.po.AsdDAO">
		<property name="sessionFactory">
			<ref bean="sessionFactory" />
		</property>
	</bean></beans>
#1

40分

修改为以下内容试一下

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
  "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
    <bean id="dataSource"
        class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName"
            value="com.mysql.jdbc.Driver">
        </property>
        <property name="url"
            value="jdbc:mysql://localhost:3306/Pokemon">
        </property>
        <property name="username" value="root"></property>
        <property name="password" value="laomin"></property>
    </bean>
    <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>
            </props>
        </property>
        <property name="mappingResources">
            <list>
                <value>com/poke/po/Manager.hbm.xml</value>
                <value>com/poke/po/Player.hbm.xml</value>
                <value>com/poke/po/Asd.hbm.xml</value></list>
        </property></bean>
    <bean id="ManagerDAO" class="com.poke.po.ManagerDAO">
        <property name="sessionFactory">
            <ref bean="sessionFactory" />
        </property>
    </bean>
    <bean id="PlayerDAO" class="com.poke.po.PlayerDAO">
        <property name="sessionFactory">
            <ref bean="sessionFactory" />
        </property>
    </bean>
    <bean id="AsdDAO" class="com.poke.po.AsdDAO">
        <property name="sessionFactory">
            <ref bean="sessionFactory" />
        </property>
    </bean></beans>




#2
其实就是 在xml文件的第一行 下面 加一行
<!DOCTYPE beans PUBLIC “-//SPRING//DTD BEAN//EN”
  “http://www.springframework.org/dtd/spring-beans.dtd”>
就可以了
#3

回复1楼:

嗯嗯,可以了,太感谢了,能告诉下我原因是什么吗?是Spring和Hibernate版本不兼容?导致不能用schema那个开头?能说说吗?

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明Hibernate反向建立hbm和dao,po时 Document is invalid: no grammar found
喜欢 (0)
[1034331897@qq.com]
分享 (0)