在entityManagerFactory bean定义中指定“ packagesToScan”和“ persistenceUnitName”属性。
<bean id="entityManagerFactory" > <property name="dataSource" ref="dataSource" /> <property name="persistenceUnitName" value="myPersistenceUnit" /> <property name="packagesToScan" > <list> <value>org.mypackage.*.model</value> </list> </property> <property name="jpaProperties"> <props> <prop key="hibernate.dialect">${hibernate.dialect}</prop> <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop> <prop key="hibernate.show_sql">${hibernate.show_sql}</prop> <prop key="hibernate.format_sql">${hibernate.format_sql}</prop> </props> </property> </bean>请注意,这适用于Spring版本> 3.1



