我有两个项目:
普通和人力资源
common项目是父项目(打包为Jar),hrm是从属项目(打包为war)
依赖关系是通过Maven指定的
Maven依赖关系指定为:
<dependency>
<groupId>com.talentera</groupId>
<artifactId>common</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
我在hrm项目中的持久性XML:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1"
xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="talentera" transaction-type="RESOURCE_LOCAL">
<description>example of enabling the second level cache.</description>
<jta-data-source>java:jboss/datasources/TalenteraDS</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<jar-file>../../lib/common-0.0.1-SNAPSHOT.jar</jar-file>
<properties>
<property name="hibernate.cache.use_second_level_cache" value="false" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
<property name="hibernate.bytecode.use_reflection_optimizer" value="false" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.use_outer_join" value="false" />
<property name="hibernate.cache.use_structured_entries" value="true" />
<property name="hibernate.generate_statistics" value="true" />
<property name="hibernate.id.new_generator_mappings" value="false" />
<property name="hibernate.default_batch_fetch_size" value="500" />
<property name="hibernate.max_fetch_depth" value="5" />
<property name="hibernate.jdbc.batch_size" value="1000" />
<property name="jboss.as.jpa.managed" value="false" />
<property name="hibernate.archive.autodetection" value="class, hbm"/>
</properties>
</persistence-unit>
</persistence>
弹簧配置:
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="appDataSource" />
<property name="persistenceUnitName" value="talentera" />
<property name="jpaVendorAdapter">
<bean
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="database" value="MYSQL" />
<property name="showSql" value="true" />
</bean>
</property>
<property name="jpaDialect">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
</property>
</bean>
<bean id="jpaTransactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
<property name="dataSource" ref="appDataSource" />
</bean>
请帮助我使这些共同点可用,以便在spring-jpa的hrm项目中自动识别
common被打包为Jar,而hrm被打包为war。
如果需要在此处提供更多信息,请告诉我。
最佳答案
我在复合单元上遇到了同样的问题,我通过以下方式解决了:
你必须改变
<jar-file>../../lib/common-0.0.1-SNAPSHOT.jar</jar-file>
与
<jar-file>WEB-INF/lib/common-0.0.1-SNAPSHOT.jar</jar-file>
ii应该工作