繁体   English   中英

hibernate 5和spring 4.1集成配置

[英]hibernate 5 and spring 4.1 integration configuration

此配置无法自动连接dao类

组态:

 <?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容器集成在一起,它不会自动装配dao类。我正在提供由我实现的代码。

放入弹簧配置:

<!-- 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" />

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM