多数据源使用spring-data-jpa无法部署到JBoss As Server
2019獨(dú)角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>
1.異常信息
Caused by: java.lang.IllegalArgumentException: JBAS011470: Persistence unitName was not specified and there are 2 persistence unit definitions in application deployment "". Either change the application to have only one persistence unit definition or specify the unitName for each reference to a persistence unit.at org.jboss.as.jpa.container.PersistenceUnitSearch.resolvePersistenceUnitSupplier(PersistenceUnitSearch.java:69)at org.jboss.as.jpa.processor.JPAAnnotationParseProcessor.getPersistenceUnit(JPAAnnotationParseProcessor.java:284)at org.jboss.as.jpa.processor.JPAAnnotationParseProcessor.getBindingSource(JPAAnnotationParseProcessor.java:220)at org.jboss.as.jpa.processor.JPAAnnotationParseProcessor.processMethod(JPAAnnotationParseProcessor.java:186)at org.jboss.as.jpa.processor.JPAAnnotationParseProcessor.processPersistenceAnnotations(JPAAnnotationParseProcessor.java:123)at org.jboss.as.jpa.processor.JPAAnnotationParseProcessor.deploy(JPAAnnotationParseProcessor.java:90)at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:113) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]2.問(wèn)題原因
1)JBoss在部署應(yīng)用時(shí),會(huì)校驗(yàn)所有被@PersistenceContext、@PersistenceUnit注解了的類(lèi)、方法及屬性
2)在應(yīng)用中如有有多個(gè)persistence units,JBoss會(huì)校驗(yàn)所有的注解是否都有unitName
public void deploy(DeploymentPhaseContext phaseContext)throws DeploymentUnitProcessingException{DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();EEModuleDescription eeModuleDescription = (EEModuleDescription)deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);CompositeIndex index = (CompositeIndex)deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.COMPOSITE_ANNOTATION_INDEX);EEApplicationClasses applicationClasses = (EEApplicationClasses)deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_APPLICATION_CLASSES_DESCRIPTION);List persistenceContexts = index.getAnnotations(PERSISTENCE_CONTEXT_ANNOTATION_NAME);processPersistenceAnnotations(deploymentUnit, eeModuleDescription, persistenceContexts, applicationClasses);List persistenceUnits = index.getAnnotations(PERSISTENCE_UNIT_ANNOTATION_NAME);processPersistenceAnnotations(deploymentUnit, eeModuleDescription, persistenceUnits, applicationClasses);if ((!persistenceContexts.isEmpty()) || (!persistenceUnits.isEmpty()))JPADeploymentMarker.mark(deploymentUnit);}
3)spring-data-jpa的jar包中的JpaRepositoryFactoryBean類(lèi)中有個(gè)表有@PersistenceContext注解的方法,且未指明unitName,所以無(wú)法通過(guò)JBoss的校驗(yàn)
public class JpaRepositoryFactoryBean<T extends Repository<S, ID>, S, ID extends Serializable> extends TransactionalRepositoryFactoryBeanSupport<T, S, ID> {private EntityManager entityManager;@PersistenceContextpublic void setEntityManager(EntityManager entityManager){this.entityManager = entityManager;}
3.問(wèn)題處理
在JBoss7.1版本中,以上問(wèn)題無(wú)法解決,根據(jù)JBoss的JIRA上的信息,這個(gè)問(wèn)題在7.2.0.Final版本中修復(fù)
4.參考資料
1)multilpe persistence units with spring-data-jpa will not deploy to JBoss AS Server
2)PersistenceUnitSearch violates the JPA spec
轉(zhuǎn)載于:https://my.oschina.net/JasonZhang/blog/540461
總結(jié)
以上是生活随笔為你收集整理的多数据源使用spring-data-jpa无法部署到JBoss As Server的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Linux下C编程实战
- 下一篇: 自定义View,圆形头像