java - 多个 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
不同。DAOclass
ParentDAOImpl
请帮助我,我是新手。
解决方案
推荐阅读
- django - Django 的容器编排自动缩放部署打开了太多与数据库的连接
- php - 如何在 laravel 中使用 2 格式进行 1 次验证?
- php - PHP - 多维数组中的高级搜索值
- asp.net - IIS 关闭所有会话而不回收应用程序池
- docker - 如何获取推送到谷歌容器注册表的图像的最新 20 个左右的图像版本(标签)?
- java - 在 OpenJDK 源代码中如何以及在何处解释分配堆内存?
- kubernetes - 存储在 apiserver 中的 Kubernetes 事件的指标
- python - 如何使用 matplotlib 实时绘制更新的 numpy ndarray?
- java - 在Android中隐藏UI元素后如何最小化滚动视图的大小?
- excel - 如何制作必须为相应行和列显示的可透视计算字段