当前位置: 首页 > 面试题库 >

Spring数据配置-找不到hibernate.properties

呼延才
2023-03-14
问题内容

我尝试基于使用Hibernate内存数据库配置Spring
Data :

<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

问题是我不想在properties文件中指定它,就像我以前没有Spring
Data一样,我想在xml配置中设置它,就像我基于的答案一样。我想念什么吗?预先感谢您的帮助。


问题答案:

那行仅是来自Hibernate的信息消息。您可能还会收到与此类似的另一个抱怨hibernate.cfg.xml

在启动时,可以使用这2个文件配置hibernate模式,而hibernate记录不存在的文件。一无所有 您可以简单地忽略它。



 类似资料:
  • 问题内容: 通过Spring-Data-Elasticsearch,我试图使用在 elasticsearch_config.json中 定义的分析器和映射。 该JSON文件位于 / src / main / resources 文件夹中。 我的JAVA模型如下所示: elasticsearch_config.json 包含设置和映射: 我尝试了curl,索引/搜索没有问题。 我的问题 : 我想使用

  • 所以,在我的工作中,我一直试图开始从Maven到Gradle的迁移,但我现在遇到了一个我似乎无法把头绕过去的严重问题。 我基本上只想为我的测试运行一些简单的liquibase迁移,为此我旋转了两个测试容器。一个用于rabbitmqexchange,一个用于postgres DB。 我使用这里描述的一个小变通方法设置了postgres容器:使用Kotlin和Testcontainers测试Sprin

  • 我使用的是Spring Boot MVC,Spring的在数据源配置之前被调用,数据源配置加载到中。 总是首先被调用,因此从来没有为Autowed定义过bean。 我尝试了从到的所有方法。我找不到一个像样的解释。但是我需要在数据源运行WebSecurity之前为它创建一个Bean

  • 当我将spring应用程序(spring 2.5.6)部署到Tomcat(6.0)上时,启动失败 我的网络。xml如下所示: 全部的xml导入许多配置文件: B.xml定义了一个数据源: C. xml创建一个Hibernate会话工厂,引用来自B. xml的数据源: 当我部署我的WAR文件时,会发生上述异常。我的问题是: > @RunWith(SpringJUnit4ClassRunner.cla

  • 请注意:这个问题不是一个骗局,我甚至引用了下面的另一个类似问题。我断言我的情况与所提到的另一个问题完全不同。 我正在建立一个SpringBootWeb服务,它没有任何数据库、JDBC或RDBMS数据源的支持。 启动时,我得到一个错误: 在这里,我看到一个非常类似的问题,在这里,公认的答案是: "您没有为Spring Boot提供足够的信息来自动配置" ...并继续解释如何在应用配置文件中设置适当的

  • Spring boot版本1.5.3