2015-08-08 168 views
0

此配置無法自動裝配DAO類休眠5,春季4.1集成配置

配置:

<?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:aop="http://www.springframework.org/schema/aop" 
      xmlns:context="http://www.springframework.org/schema/context" 
      xmlns:jee="http://www.springframework.org/schema/jee" 
      xmlns:lang="http://www.springframework.org/schema/lang" 
      xmlns:p="http://www.springframework.org/schema/p" 
      xmlns:tx="http://www.springframework.org/schema/tx" 
      xmlns:util="http://www.springframework.org/schema/util" 
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd 
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd 
       http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd 
       http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd 
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd 
       http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"> 
     <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> 
<property name="dataSource" ref="dataSource" /> 
       <property name="annotatedClasses"> 
     <list> 
     <value>a.b.c.MyEntity</value> 
     </list> 
     </property> 

       <property name="hibernateProperties"> 
        <props> 
         <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop> 
        <prop key="hibernate.show_sql">true</prop> 
         <prop key ="format_sql">true</prop>   
         <prop key="hibernate.bytecode.use_reflection_optimizer">true</prop> 
         <prop key="hibernate.order_updates">true</prop> 
         <prop key="hibernate.connection.autocommit">false</prop> 
        </props> 
       </property> 
      </bean> 
      <tx:annotation-driven/> 
      <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> 
       <property name="sessionFactory" ref="sessionFactory" /> 
      </bean> 
      <bean id="dataSource" 
        class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 
        <property name="driverClassName" value="org.postgresql.Driver" /> 
        <property name="url" value="jdbc:postgresql://dbserver:5432/dbname" /> 
        <property name="username" value="postgres" /> 
        <property name="password" value="" /> 
      </bean> 
      <bean id="persistenceExceptionTranslationPostProcessor" class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" /> 
     </beans>  

我想hibernat 5與註釋Spring容器集成, 它不會自動裝配道我正在提供由我執行的代碼。

回答

0

把你的Spring配置:

<!-- Register Annotation-based Post Processing Beans --> 
<context:annotation-config /> 

<!-- Scan context package for any eligible annotation configured beans. --> 
<context:component-scan base-package="your.package" /> 
+0

Glawacz我已經嘗試過了,但它掃描所有服務註釋,但不自動裝配庫註解類 –

+0

張貼在你的問題你的DAO實現。 –