首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

一个简单的struts,spring整合Hibernate时,加载XML文件出错解决思路

2012-03-01 
一个简单的struts,spring整合Hibernate时,加载XML文件出错User.hbm.xml如下:?xmlversion 1.0 encoding

一个简单的struts,spring整合Hibernate时,加载XML文件出错
User.hbm.xml如下:

<?xml   version= "1.0 "   encoding= "UTF-8 "?>
<!DOCTYPE   hibernate-mapping   PUBLIC   "-//Hibernate/Hibernate   Mapping   DTD   2.0//EN "   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd "   >
       
<hibernate-mapping>
<!--  
        Created   by   the   Middlegen   Hibernate   plugin   2.1

        http://boss.bekk.no/boss/middlegen/
        http://www.hibernate.org/
-->

<class  
        name= "com.neusoft.vo.User "  
        table= "user "
>
   
        <id
                name= "id "
                type= "java.lang.String "
                column= "id "
        >
        <generator   class= "uuid.hex "   />
        </id>

        <property
                name= "username "
                type= "java.lang.String "
                column= "username "
                not-null= "true "
                length= "32 "
        />
     
        <property
                name= "password "
                type= "java.lang.String "
                column= "password "
                not-null= "true "
                length= "32 "
        />
             
     
        <!--   Associations   -->
   

</class>
</hibernate-mapping>


spring配置文件如下:

<?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 "   destroy-method= "close ">
    <property   name= "driverClassName ">
      <value> com.mysql.jdbc.Driver </value>
    </property>
    <property   name= "url ">
      <value> jdbc:mysql://localhost/test </value>
    </property>
    <property   name= "username ">


      <value> root </value>
    </property>
    <property   name= "password ">
      <value> mysql </value>
    </property>
  </bean>

<!--   和HIBERNATE联系起来   -->
<bean   id= "sessionFactory "   class= "org.springframework.orm.hibernate3.LocalSessionFactoryBean ">
    <property   name= "dataSource ">
      <ref   local= "dataSource "   />
    </property>
    <property   name= "mappingResources ">
      <list>
        <value> /com/neusoft/vo/User.hbm.xml </value>
      </list>
    </property>
    <property   name= "hibernateProperties ">
      <props>
        <prop   key= "hibernate.dialect "> org.hibernate.dialect.MySQLDialect </prop>
        <prop   key= "hibernate.show_sql "> true </prop>
      </props>
    </property>
  </bean>


<!--   进行事务处理   -->
<bean   id= "transactionManager "   class= "org.springframework.orm.hibernate3.HibernateTransactionManager ">
    <property   name= "sessionFactory ">
      <ref   local= "sessionFactory "   />
    </property>
  </bean>


<!--   进行DAO代理   -->
<bean   id= "userDAOProxy "   class= "org.springframework.transaction.interceptor.TransactionProxyFactoryBean ">
    <property   name= "transactionManager ">
      <ref   bean= "transactionManager "   />
    </property>
    <property   name= "target ">
      <ref   local= "userDAO "   />
    </property>
    <property   name= "transactionAttributes ">
      <props>
        <prop   key= "insert* "> PROPAGATION_REQUIRED </prop>
        <prop   key= "get* "> PROPAGATION_REQUIRED,readOnly </prop>
        <prop   key= "is* "> PROPAGATION_REQUIRED,readOnly </prop>
      </props>
    </property>
  </bean>


<bean   id= "userDAO "   class= "com.neusoft.dao.impl.UserDAOImpl ">
<property   name= "sessionFactory ">
      <ref   local= "sessionFactory "   />
    </property>
  </bean>

<bean   id= "rege "   class= "com.neusoft.service.impl.RegeditImpl ">
<property   name= "userDAO "> <ref   bean= "userDAOProxy "/>   </property>
</bean>

<bean   name= "/regeditte "   class= "com.neusoft.action.RegeditAction "   >


<property   name= "regedit "> <ref   bean= "rege "   />   </property>
</bean>
<!-- <bean   name= "/regeditte "   class= "com.neusoft.action.RegeditAction "   >
<property   name= "userDAO "> <ref   bean= "userDAOProxy "   />   </property> </bean> -->
</beans>


错误提示:

2007-09-10   15:54:23   StandardContext[/mySSH]Initializing   WebApplicationContext   for   Struts   ActionServlet   'actionServlet ',   module   ' '
2007-09-10   15:54:48   StandardContext[/mySSH]actionServlet:   null
org.springframework.beans.factory.BeanCreationException:   Error   creating   bean   with   name   'sessionFactory '   defined   in   ServletContext   resource   [/WEB-INF/spring-config.xml]:   Invocation   of   init   method   failed;   nested   exception   is   org.hibernate.InvalidMappingException:   Could   not   parse   mapping   document   from   input   stream
Caused   by:   org.hibernate.InvalidMappingException:   Could   not   parse   mapping   document   from   input   stream
at   org.hibernate.cfg.Configuration.addInputStream(Configuration.java:508)
at   org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:656)


[解决办法]
up

热点排行