我正在从WF 7.4.0迁移。最终比分为16.0.0。最终的在解决了不同模块的升级问题后,我遇到了以下问题:一个不明确的依赖项异常。如何保持与两个数据库的连接?
SessionFactory hibernate-core-5.3.9现在似乎是从EntityManagerFactory扩展过来的,而它没有扩展到hibernate-core-4.2.14(WF7.4)。SessionFactory在HibernateProducer中定义,一个单独的实例被注入环境生产者(特别是针对jbpm)。这两个实例似乎在Wildfly 7.4中没有的地方相互干扰。
它连接到两个数据库:一个jbpm和一个特定于应用程序的数据库。这两个数据库都定义了persistence.xml。
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Disposes;
import javax.enterprise.inject.Produces;
import javax.persistence.PersistenceUnit;
public class HibernateProducer {
@Produces
@ApplicationScoped
public SessionFactory getSessionFactory() {
Configuration configuration = new Configuration();
configuration.configure();
return configuration.buildSessionFactory();
}
public void closeSessionFactory(@Disposes SessionFactory sessionFactory) {
sessionFactory.close();
}
}
import org.jbpm.persistence.JpaProcessPersistenceContextManager;
import org.jbpm.persistence.jta.ContainerManagedTransactionManager;
import org.jbpm.process.audit.JPAWorkingMemoryDbLogger;
import org.jbpm.process.core.timer.GlobalSchedulerService;
import org.jbpm.runtime.manager.impl.DefaultRuntimeEnvironment;
import org.jbpm.services.cdi.impl.manager.InjectableRegisterableItemsFactory;
import org.jbpm.services.task.persistence.JPATaskPersistenceContextManager;
import org.kie.api.io.Resource;
import org.kie.api.io.ResourceType;
import org.kie.api.runtime.Environment;
import org.kie.api.runtime.EnvironmentName;
import org.kie.api.task.UserGroupCallback;
import org.kie.internal.runtime.manager.RuntimeEnvironment;
import org.kie.internal.runtime.manager.cdi.qualifier.PerProcessInstance;
import org.kie.internal.runtime.manager.cdi.qualifier.PerRequest;
import org.kie.internal.runtime.manager.cdi.qualifier.Singleton;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Instance;
import javax.enterprise.inject.Produces;
import javax.enterprise.inject.spi.BeanManager;
import javax.inject.Inject;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceUnit;
@ApplicationScoped
public class EnvironmentProducer {
@Inject
protected BeanManager beanManager;
@Inject
protected CDIGlobalResolver globalResolver;
@Inject
protected GlobalSchedulerService schedulerService;
@Inject
protected UserGroupCallback userGroupCallback;
@PersistenceUnit(unitName = "org.jbpm.domain")
protected EntityManagerFactory emf;
// @Inject
// protected ContainerManagedTransactionManager transactionManager;
@Inject
private Instance<ResourceProducer> resourceProducers;
@Produces
@Singleton
@PerRequest
@PerProcessInstance
public RuntimeEnvironment produceEnvironment() {
DefaultRuntimeEnvironment runtimeEnvironment = new DefaultRuntimeEnvironment();
runtimeEnvironment.addToConfiguration("drools.commandService",
SingleThreadCommandService.class.getName());
runtimeEnvironment.setEmf(emf);
runtimeEnvironment.setSchedulerService(schedulerService);
runtimeEnvironment.setUserGroupCallback(userGroupCallback);
runtimeEnvironment
.setRegisterableItemsFactory(InjectableRegisterableItemsFactory
.getFactory(beanManager, new JPAWorkingMemoryDbLogger(
emf)));
Environment env = runtimeEnvironment.getEnvironmentTemplate();
runtimeEnvironment.addToConfiguration("drools.commandService",
SingleThreadCommandService.class.getName());
runtimeEnvironment.addToEnvironment(EnvironmentName.GLOBALS,
globalResolver);
runtimeEnvironment.addToEnvironment(
EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
runtimeEnvironment.addToEnvironment(
EnvironmentName.TRANSACTION_MANAGER, new ContainerManagedTransactionManager());
runtimeEnvironment.addToEnvironment(
EnvironmentName.PERSISTENCE_CONTEXT_MANAGER,
new JpaProcessPersistenceContextManager(env));
runtimeEnvironment.addToEnvironment(
EnvironmentName.TASK_PERSISTENCE_CONTEXT_MANAGER,
new JPATaskPersistenceContextManager(env));
for (ResourceProducer resourceProducer : resourceProducers) {
ResourceType resourceType = resourceProducer.getResourceType();
for (Resource resource : resourceProducer.getResources()) {
runtimeEnvironment.addAsset(resource, resourceType);
}
}
runtimeEnvironment.init();
return runtimeEnvironment;
}
@Produces
@ApplicationScoped
//@Named
public EntityManagerFactory getEntityManagerFactory() {
return emf;
}
}
Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001409: Ambiguous dependencies for type EntityManagerFactory with qualifiers @Default
at injection point [BackedAnnotatedParameter] Parameter 1 of [BackedAnnotatedMethod] @Inject public be.bside.process.jbpm.service.ProcessEngineService.init(EntityManagerFactory)
at be.bside.process.jbpm.service.ProcessEngineService.init(ProcessEngineService.java:0)
Possible dependencies:
- Producer Method [SessionFactory] with qualifiers [@Any @Default] declared as [[BackedAnnotatedMethod] @Produces @ApplicationScoped public be.bside.common.store.HibernateProducer.getSessionFactory()],
- Producer Method [EntityManagerFactory] with qualifiers [@Any @Default] declared as [[BackedAnnotatedMethod] @Produces @ApplicationScoped public be.bside.process.jbpm.service.EnvironmentProducer.getEntityManagerFactory()]
如果您试图使用两个不同的EntityManagerFactory,则使用限定符来区分。
一个简单的修复方法是在您的HibernateProducer#getSessionFactory()方法上添加@Type(SessionFactory.class)
。
我正试图将我的JSF应用程序迁移到CDI。我已经暗示了以下变化: null deploymentException:WELD-001409类型[EagerBeansRepository]在注入点[[BakedAnnotatedField]@inject private org.omnifaces.applicationListener.EagerBeansRepository]具有限定符[@def
我正在运行一个JUnit测试,嗯,我的Spring启动项目,我是这样写的: 找到依赖项[com.br.suppcomm.ocp.dao.logindao]得[com.br.suppcomm.ocp.dao.logindao]:需要至少1个具有此依赖项自动候选资格得bean.依赖项注释:{@org.SpringFramework.Beans.Factory.Annotation.AutoWired(
Dependencies serve many different purposes. Some dependencies are needed to build your project, others are needed when you’re running your program. As such there are a number of different types of dep
我在父POM中声明 此外,儿童pom使用 一切正常吗?但是当我在type = pom中使用这种依赖关系时 我有错误 如何在dependencyManagement中用type = POM $ { Jboss-javaee-7.0 . version }声明一个依赖项如果我在根中带有Jboss-javaee-7.0,那么运行
当我试图在SpringMVC中使用依赖注入时,我遇到了这个错误。 没有匹配的类型[com.sachin.dao.斯托克道]的bean找到依赖项:预计至少有1 bean有资格作为该依赖项的自动连接候选。依赖注释:{};嵌套异常是org.springframework.beans.factory.NoSuchBean定义异常:没有找到类型[com.sachin.dao.Stock道]的匹配bean的依