请查看下
<jdbc:embedded-database type="H2" id="dataSource">
</jdbc:embedded-database>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
p:dataSource-ref="dataSource" p:packagesToScan="org.spring.web.example.domain">
<property name="jpaVendorAdapter">
<bean id="jpaAdapter"
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"
p:generateDdl="true" p:showSql="true" p:databasePlatform="org.hibernate.dialect.MySQLDialect" />
</property>
</bean>
配置这种配置是定义上的嵌入式数据库的数据源,你可以改变它是你喜欢则定义JPA的DAO使用的entityManagerFactory作为
任何数据库
protected EntityManager entityManager;
public EntityManager getEntityManager() {
return entityManager;
}
@PersistenceContext
public void setEntityManager(EntityManager entityManager) {
this.entityManager = entityManager;
}
检查link
对我来说我目前使用弹簧数据JpaRepository代替肌酐的NG DAO从无到有,
,如果你想添加的事务使用:
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"
p:entityManagerFactory-ref="entityManagerFactory" />
<tx:annotation-driven />
那么你可以使用@Transaction
还要检查这个channel
你检查这个例子,它说明你需要的一切。 https://github.com/SpringSource/spring-data-jpa-examples – Jaiwo99 2013-04-29 09:30:47