簡體   English   中英

LocalContainerEntityManagerFactoryBean hibernate 配置bean循環初始化

[英]LocalContainerEntityManagerFactoryBean hibernate configuration bean is initialized in a loop

I have my hibernate entity manager factory declared in jpa.xml, hazecast configured in hazelcast.xml and I have domain model setup and I have corresponding componentContext.xml present in the domain model project where my entity manager factory class is implemented in it. 但我面臨的問題是我在 componentContext.xml 中的 bean 正在循環中初始化(從 hibernate.log 觀察到)

我的 Web.xml 只配置了 com.sun.faces.config.ConfigureListener listenere。

我的堆棧 Spring - 4.3.8 Hibernate - 5.0.10-FINAL hazelcast-hibernate5 - 1.3.0

JPA.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
  xsi:schemaLocation="http://www.springframework.org/schema/beans 
                           http://www.springframework.org/schema/beans/spring-beans.xsd 
                           http://www.springframework.org/schema/context 
                           http://www.springframework.org/schema/context/spring-context.xsd">

  <context:property-placeholder location="classpath:dataSources.properties" />

  <!-- Default JPA configuration for OpenJPA and Hibernate -->


  <!-- Hibernate configuration -->
  <bean id="hibernateEntityManagerFactory" abstract="true" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="jpaPropertyMap">
      <map>
        <entry key="hibernate.max_fetch_depth" value="3" />
        <entry key="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider" />
        <entry key="hibernate.enable_lazy_load_no_trans" value="true" />
        <entry key="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform" />
        <entry key="hibernate.current_session_context_class" value="jta" />

      </map>
    </property>
    <property name="jpaVendorAdapter">
      <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
        <property name="database" value="${dbDialect}" />
      </bean>
    </property>
  </bean>

  <alias name="hibernateEntityManagerFactory" alias="entityManagerFactory" />

</beans>

組件上下文.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:cache="http://www.springframework.org/schema/cache" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:context="http://www.springframework.org/schema/context"
  xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd"
  xmlns:jpa="http://www.springframework.org/schema/data/jpa">

  <context:component-scan base-package="com.volvo.myfirstdomain.base />
  <context:annotation-config />

  <!-- JPA EntityManagerFactory -->
  <!-- Based on choice of implementation between OpenJPA and Hibernate, parent attribute in bean should be set. For OpenJPA: parent = "openJpaEntityManagerFactory" 
    For Hibernate: parent = "hibernateEntityManagerFactory" Here, OpenJPA is chosen as you can see below. -->
  <bean id="myDomainEntityManagerFactory" parent="entityManagerFactory">
    <property name="persistenceUnitName" value="MYDomainPU" />
    <property name="packagesToScan" value="com.volvo.myfirstdomain.entity" />

    <property name="jpaProperties">
      <props>
        <prop key="hibernate.default_schema">DOMAIN_ONE</prop>
        <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect </prop>
        <prop key="hibernate.cache.region.factory_class">com.hazelcast.hibernate.HazelcastCacheRegionFactory</prop>
        <prop key="hibernate.cache.use_second_level_cache">true</prop>
        <prop key="hibernate.cache.use_query_cache">true</prop>
        <prop key="javax.persistence.sharedCache.mode">ENABLE_SELECTIVE</prop>

      </props>
    </property>

  </bean>

  <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
    <constructor-arg ref="dataSource" />
  </bean>
</beans>

我已經嘗試過多次調試,但我無法弄清楚為什么初始化會發生多次(就像在循環中一樣)。 任何指針都非常感謝!

我終於弄清楚了原因。 在應用程序配置 class 中指定了一個額外的 @ComponentScan 注釋,導致循環被觸發。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM