# Spring集成Hibernate注解配置 无hibernate.cfg.xml文件，自动生成表配置

> Author: OneCoder (李宏哲) | Canonical: https://www.coderli.com/spring-hibernate-hbm2dll-config/
> Published: 2014-05-09 | Topic: Java 架构演进与实战 / 架构实践
> Tags: Spring, Hibernate

<p>
	本以为一个无足挂齿的小问题，没想到还折腾了一下。遂记录一下。主要搜索出的结果排名靠前的大多是在hibernate.cfg.xml中的配置方式。与我的环境不符。正确配置方式如下。已测试。</p>

```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 >
```

<p>
	注：注释掉的配置value配置方式和prop配置方式，均有效。<br />
	&nbsp;</p>

---
Source: OneCoder (https://www.coderli.com/spring-hibernate-hbm2dll-config/) | GESP Wiki: https://wiki.coderli.com/ | OI-Game: https://oi.coderli.com/
