多数据源使用spring-data-jpa无法部署到JBoss As Server
生活随笔
收集整理的這篇文章主要介紹了
多数据源使用spring-data-jpa无法部署到JBoss As Server
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
2019獨角獸企業(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.問題原因
1)JBoss在部署應(yīng)用時,會校驗所有被@PersistenceContext、@PersistenceUnit注解了的類、方法及屬性
2)在應(yīng)用中如有有多個persistence units,JBoss會校驗所有的注解是否都有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類中有個表有@PersistenceContext注解的方法,且未指明unitName,所以無法通過JBoss的校驗
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.問題處理
在JBoss7.1版本中,以上問題無法解決,根據(jù)JBoss的JIRA上的信息,這個問題在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的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Linux下C编程实战
- 下一篇: 自定义View,圆形头像