【发布时间】:2012-02-12 06:27:12
【问题描述】:
如你所知,在 spring applicationContext 中,我们可以从 persistence.xml 定义 entityManagerFactory bean,就像:
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="MyUnit" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="true" />
<property name="generateDdl" value="false" />
<property name="database" value="MYSQL" />
</bean>
</property>
</bean>
现在如果我想初始化数据库如下:
<jdbc:initialize-database data-source="myDataSource" enabled="true">
<jdbc:script location="classpath*:com/myapp/data*.sql"/>
</jdbc:initialize-database>
我应该为它配置另一个数据源bean吗?或者我可以参考上面定义的 emf,或者可以参考persistence.xml?
【问题讨论】:
-
@skaffman:来自 Spring 参考:12.9.1 Initializing a database instance using Spring XML “如果要初始化数据库并且可以提供对 DataSource bean 的引用,请使用初始化-spring-jdbc 命名空间中的数据源标签:"
标签: spring jpa jdbc initialization