如何修复此异常? 它阻止我启动 Helidon 服务器。 我正在从 Eclipse IDE 运行 TestNG。 如果我执行
mvn clean package
,则不会发生这种情况。
...
Caused by: org.jboss.weld.exceptions.AmbiguousResolutionException: WELD-001335: Ambiguous dependencies for type PersistenceProvider with qualifiers
Possible dependencies:
- Configurator Bean [class io.helidon.integrations.cdi.jpa.JpaExtension, types: PersistenceProvider, Object, DelegatePersistenceProvider, LogPersistenceProvider, qualifiers: @Any @Default],
- Configurator Bean [class io.helidon.integrations.cdi.jpa.JpaExtension, types: PersistenceProvider, qualifiers: @Default @Any @Named]
at org.jboss.weld.bean.builtin.InstanceImpl.checkBeanResolved(InstanceImpl.java:244)
at org.jboss.weld.bean.builtin.InstanceImpl.get(InstanceImpl.java:113)
at org.jboss.weld.util.ForwardingWeldInstance.get(ForwardingWeldInstance.java:44)
at io.helidon.integrations.cdi.jpa.EntityManagerFactories.getPersistenceProvider(EntityManagerFactories.java:222)
at io.helidon.integrations.cdi.jpa.EntityManagerFactories.createContainerManagedEntityManagerFactory(EntityManagerFactories.java:161)
at io.helidon.integrations.cdi.jpa.JpaExtension.lambda$addContainerManagedEntityManagerFactoryBeans$1(JpaExtension.java:1033)
at org.jboss.weld.bootstrap.events.configurator.BeanConfiguratorImpl$CreateCallback.create(BeanConfiguratorImpl.java:372)
at org.jboss.weld.bootstrap.events.configurator.BeanConfiguratorImpl$CreateCallback.access$700(BeanConfiguratorImpl.java:339)
at org.jboss.weld.bootstrap.events.configurator.BeanConfiguratorImpl$ImmutableBean.create(BeanConfiguratorImpl.java:511)
at org.jboss.weld.contexts.AbstractContext.get(AbstractContext.java:96)
at org.jboss.weld.bean.ContextualInstanceStrategy$DefaultContextualInstanceStrategy.get(ContextualInstanceStrategy.java:100)
at org.jboss.weld.bean.ContextualInstance.get(ContextualInstance.java:50)
at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:102)
at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:105)
at io.helidon.integrations.cdi.jpa.EntityManagerFactory$_$$_WeldClientProxy.isOpen(Unknown Source)
at io.helidon.integrations.cdi.jpa.JpaExtension.onStartup(JpaExtension.java:2053)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:569)
at org.jboss.weld.injection.StaticMethodInjectionPoint.invoke(StaticMethodInjectionPoint.java:95)
at org.jboss.weld.injection.StaticMethodInjectionPoint.invoke(StaticMethodInjectionPoint.java:85)
at org.jboss.weld.injection.MethodInvocationStrategy$DefaultMethodInvocationStrategy.invoke(MethodInvocationStrategy.java:144)
at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:330)
at org.jboss.weld.event.ExtensionObserverMethodImpl.sendEvent(ExtensionObserverMethodImpl.java:123)
at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:308)
at org.jboss.weld.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:286)
at jakarta.enterprise.inject.spi.ObserverMethod.notify(ObserverMethod.java:125)
at org.jboss.weld.util.Observers.notify(Observers.java:166)
at org.jboss.weld.event.ObserverNotifier.notifySyncObservers(ObserverNotifier.java:285)
at org.jboss.weld.event.ObserverNotifier.notify(ObserverNotifier.java:273)
at org.jboss.weld.event.EventImpl.fire(EventImpl.java:96)
at io.helidon.microprofile.cdi.HelidonContainerImpl.doStart(HelidonContainerImpl.java:340)
at io.helidon.common.context.Contexts.runInContext(Contexts.java:137)
at io.helidon.microprofile.cdi.HelidonContainerImpl.start(HelidonContainerImpl.java:250)
at io.helidon.microprofile.server.ServerImpl.start(ServerImpl.java:76)
主 Eclipse 项目有一个也在 Eclipse 中的依赖项目。 依赖项目生成
/target/classes/META-INF/persistence.xml
.
当使用
mvn
构建依赖项目时,maven-jar-plugin
不包括META-INF/persistence.xml
。 所以,Maven 构建工作。
当主项目在 Eclipse 中运行时,Eclipse 会包含依赖项目
persistence.xml
。 主项目还有一个persistence.xml
。 这使得 2 persistence.xml
可用于 Weld。 Weld然后不知道如何处理2PersistenceProvider
s.
解决方案是从依赖项目中删除
persistence.xml
。 主项目代码在启动 Helidon 服务器之前执行此操作。