首页 > 解决方案 > 多个 entityMangagerFactories(使用 1PC 模式)导致 java.lang.IllegalStateException: 'url' not set 异常

问题描述

我有使用 Java 11 的 Spring Maven 项目。Jboss WIldfly 15.0.1 Final 是我的部署服务器。

要将数据(使用 Hibernate 的对象)从一个数据源导入到另一个数据源(MySQL)- 我添加了一个主要entityManagerFactory的,JpaTransactionManager并且我有 2 个单独的实体管理器工厂perisistenceUnits和一个chainedTransactionManager正在使用的(用于 1 Phase commit-1PC commnit)。

在部署战争时,有时,我得到以下异常:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name
 'someDAO': Injection of persistence dependencies failed; nested exception is 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name
 'onetimeConfig': Injection of persistence dependencies failed; nested exception is
 org.springframework.beans.factory.BeanCreationException: Error creating bean with name
 'entityMgrFactory2' defined in class path resource [com/path/ImportConfig.class]: Bean 
instantiation via factory method failed; nested exception is
 org.springframework.beans.BeanInstantiationException: Failed to instantiate
 [javax.persistence.EntityManagerFactory]: Factory method 'entityMgrFactory2' threw exception;
 nested exception is java.lang.IllegalStateException: 'url' not set

someDAO 类头是:

@Transactional(rollbackFor = {Exception.class})
@Repository("someDAO")
public class SomeDAOImpl extends ParentDAOImpl implements SomeDAO {

该类someDAO扩展了使用ParentDAOImpl主类的类,entityManagerFactory也使用@DependsOn. 那么,为什么 on deploy 的创建someDAO是在尝试触发创建的entityMgrFactory2时候entityManagerFactory提到的呢?!

@Repository("parentDAOImpl")
@DependsOn({"entityManagerFactory"})
public class ParentDAOImpl implements ParentDAO, Serializable {
    @PersistenceContext
    private transient EntityManager entityManager;
    ...

该问题永远不会在我的本地计算机上复制。它仅在部署在其他服务器上时才会发生,并且因此部署失败。而且有时会提到例外情况,有时会有所someDAO不同。DAOclassParentDAOImpl

请帮助我,我是新手。

标签: javaspring-bootspring-transactionsspring-ormspring-data-commons

解决方案


推荐阅读