Компонент конфигурации LocalContainerEntityManagerFactoryBean hibernate инициализируется в цикле

У меня есть моя фабрика диспетчера сущностей гибернации, объявленная в jpa.xml, hazecast, настроенная в hazelcast.xml, и у меня есть настройка модели домена, и у меня есть соответствующий componentContext.xml, присутствующий в проекте модели домена, где мой класс фабрики диспетчера сущностей реализован в нем. Но проблема, с которой я столкнулся, заключается в том, что мой bean-компонент в componentContext.xml инициализируется в цикле (наблюдается из hibernate.log)

В моем Web.xml настроен только прослушиватель com.sun.faces.config.ConfigureListener.

My Stack 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>

Я несколько раз пытался отладить, но не могу понять, почему инициализация происходит несколько раз (как в цикле). Любые указатели с благодарностью!


person user1734698    schedule 30.09.2019    source источник


Ответы (1)


Наконец-то я понял причину! В классе конфигурации приложения была указана дополнительная аннотация @ComponentScan, которая вызывала запуск цикла.

person user1734698    schedule 18.11.2019