Spring JPAはマルチJARパッケージの@Entityクラスの問題をスキャンできません

1524 ワード

質問の説明:プロジェクトではMaven管理を使用して、プロジェクトを複数のサブモジュールに分割し、各サブモジュールに独自のモジュールのエンティティクラスがあります.メインモジュールでSpring JPAを使用する構成は次のとおりです.

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource"/> 
    <property name="persistenceUnitName" value="persistence"/>
    <property name="jpaVendorAdapter" ref="hibernateJpaVendorAdapter"/> 
    <property name="jpaProperties">
        <props>
            <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.SingletonEhCacheRegionFactory</prop>
            <prop key="net.sf.ehcache.configurationResourceName">ehcache/ehcache-hibernate-local.xml</prop>
            <prop key="hibernate.ejb.naming_strategy">org.hibernate.cfg.ImprovedNamingStrategy</prop>
        </props>
    </property>
</bean>

これにより、サブモジュールJARのエンティティークラスがスキャンされないという問題が発生します.
問題の解決策は次のとおりです.

1.       entityManagerFactory    :
    <property name="persistenceUnitName" value="persistence"/>;
2.      entityManagerFactory  :
    <property name="packagesToScan" value="   Entity   "/>
3.    persistence       ;