1. 程式人生 > >Spring整合Hibernate註解配置 無hibernate.cfg.xml檔案,自動生成表配置

Spring整合Hibernate註解配置 無hibernate.cfg.xml檔案,自動生成表配置

本以為一個無足掛齒的小問題,沒想到還折騰了一下。遂記錄一下。主要搜尋出的結果排名靠前的大多是在hibernate.cfg.xml中的配置方式。與我的環境不符。正確配置方式如下。已測試。

<bean id= "sessionFactory"
           class= "org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" >
           <property name ="dataSource">
               <ref bean =
"dataSource" /> </property > <property name ="packagesToScan" value= "xxx.xxx" /> <property name ="hibernateProperties"> <props > <prop key= "hibernate.hbm2ddl.auto">create</prop > </props >
<!-- <value>hibernate.hbm2ddl.auto=create</value> --> </property > </bean >

注:註釋掉的配置value配置方式和prop配置方式,均有效。