我尝试使用 Hibernate 内存数据库配置 Spring Data,基于 this和 this答案:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/data/jpa
http://www.springframework.org/schema/data/jpa/spring-jpa-1.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd">
<!-- Configure the data source bean -->
<jdbc:embedded-database id="dataSource" type="HSQL">
</jdbc:embedded-database>
<!-- Create default configuration for Hibernate -->
<bean id="hibernateJpaVendorAdapter"
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="generateDdl" value="false">
</property>
</bean>
<!-- Configure the entity manager factory bean -->
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="jpaVendorAdapter" ref="hibernateJpaVendorAdapter"/>
<property name="persistenceUnitName" value="punit"/>
<property name="jpaPropertyMap">
<map>
<entry key="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"></entry>
<entry key="hibernate.hbm2ddl.auto" value="create"></entry>
<entry key="hibernate.show_sql" value="true"></entry>
</map>
</property>
<property name="packagesToScan" value="models"/>
<property name="sharedCacheMode" value="ENABLE_SELECTIVE"/>
<property name="validationMode" value="NONE"/>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<tx:annotation-driven/>
<jpa:repositories base-package="beans.repositories"/>
但是我一遍又一遍地得到:
org.hibernate.cfg.Environment. HHH000206: hibernate.properties not found
问题是我不想在 properties
文件中指定它,因为我以前没有 Spring Data 我想在 xml
配置中设置它,比如我根据的答案。我错过了什么吗?提前感谢您的帮助。
最佳答案
该行只不过是来自 Hibernate 的信息消息。您可能会得到另一个与此类似的提示 hibernate.cfg.xml
的问题。
在启动时,hibernate 可以使用这 2 个文件进行配置,如果没有这些文件,hibernate 会记录下来。仅此而已。您可以忽略它。
关于java - Spring Data 配置 - 找不到 hibernate.properties,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39558028/