LocalContainerEntityManagerFactoryBean休眠配置bean在循环中初始化

问题描述 投票:0回答:1

我在jpa.xml中声明了我的休眠实体管理器工厂,在hazelcast.xml中配置了hazecast,并且我设置了域模型,并且在其中实现了我的实体管理器工厂类的域模型项目中也存在相应的componentContext.xml。 。但是我的问题是面临的问题是我的componentContext.xml中的bean正在初始化(从hibernate.log中观察到)]

我的Web.xml仅配置了com.sun.faces.config.ConfigureListener侦听器。

我的堆栈春季-4.3.8休眠-5.0.10-FINALhazelcast-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>

componentContext.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>

我已经尝试调试多次,但是我无法弄清为什么初始化多次发生(就像在循环中一样)。任何指针都非常感谢!

spring-4 hibernate-5.x
1个回答
0
投票
我终于弄清楚了原因!在应用程序配置类中指定了一个额外的@ComponentScan批注,这导致触发了循环。
© www.soinside.com 2019 - 2024. All rights reserved.