0

この構成の何が問題になっていますか?Spring3とHibernate3.6を使用しており、DAOを使用するように設定しようとしています。hibernate.cfg.xmlに2つのエラーが表示されます。

1つ目はセッションファクトリタグにあります-

 The content of element type "session-factory" must match 
"(property*,mapping*,(class-cache|collection-cache)*,event*,listener*)".

2つ目は--propertyname= "dataSource"--tag-にあります

The content of element type "property" must match "null".

application-context.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:mvc="http://www.springframework.org/schema/mvc"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:aop="http://www.springframework.org/schema/aop"
        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/aop
            http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context-3.0.xsd
            http://www.springframework.org/schema/mvc
            http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
    <bean id="dataSource" 
    class="org.apache.tomcat.dbcp.dbcp.BasicDataSource">
      <property name="driverClassName">
        <value>com.mysql.jdbc.Driver</value>
      </property>
      <property name="url">
        <value>jdbc:mysql://localhost/projectName</value>
      </property>
      <property name="username">
        <value>uname</value>
      </property>
      <property name="password">
        <value>pass</value>
      </property>
      <!-- Disable the second-level cache  -->
        <!-- Echo all executed SQL to stdout -->
    </bean>
    </beans>

hibernate.cfg.xml

<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
    "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
    <!-- Database connection settings -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource">
       <ref bean="dataSource"/>
    </property>
    </bean>
    <!-- SQL dialect -->
    <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
    <!-- Disable the second-level cache  -->
    <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
    <!-- Echo all executed SQL to stdout -->
    <property name="show_sql">true</property>
    <property name="transaction.factory_class">
    org.hibernate.transaction.JDBCTransactionFactory
    </property>
    <property name="current_session_context_class">
    thread
    </property>
    <mapping class="com.projectname.model.name"/>
    <mapping class="com.projectname.model.stuff"/> 
</session-factory>
</hibernate-configuration>
4

1 に答える 1

2

Hibernate と Spring の構成を混在させました。それらは完全に分離されています。Hibernate 構成内で Spring Bean を使用することはできません。

これは、Spring 構成に移動する必要があります。

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
   <ref bean="dataSource"/>
</property>    
  <!-- SQL dialect -->
  <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
  <!-- Disable the second-level cache  -->
  <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
  <!-- Echo all executed SQL to stdout -->
  <property name="show_sql">true</property>
  <property name="transaction.factory_class">
   org.hibernate.transaction.JDBCTransactionFactory
  </property>
  <property name="current_session_context_class">
  thread
  </property>
</bean>

私は通常アノテーション構成を使用するため、小さなことで誤解される可能性がありますが、ドキュメントに戻る必要があります。

于 2011-06-14T03:50:48.360 に答える