0

We have an existing application working with Spring 4 and we are trying to migrate to Weld CDI. The application is a multi war application with an ear deployment. When I try to start the WildFly server, I run into the following error:

17:18:10,299 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "posa.ear")]) - failure description: {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"posa.ear\".WeldStartService" => "Failed to start service
    Caused by: org.jboss.weld.exceptions.DefinitionException: Exception List with 1 exceptions:
Exception 0 :
javax.enterprise.inject.UnsatisfiedResolutionException: Unable to resolve a bean for 'org.springframework.data.mongodb.core.MongoOperations' with qualifiers [@javax.enterprise.inject.Default(), @javax.enterprise.inject.Any()].
    at deployment.posa.ear//org.springframework.data.mongodb.repository.cdi.MongoRepositoryExtension.createRepositoryBean(MongoRepositoryExtension.java:109)
    at deployment.posa.ear//org.springframework.data.mongodb.repository.cdi.MongoRepositoryExtension.afterBeanDiscovery(MongoRepositoryExtension.java:81)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.jboss.weld.core@3.1.3.Final//org.jboss.weld.injection.StaticMethodInjectionPoint.invoke(StaticMethodInjectionPoint.java:95)
    at org.jboss.weld.core@3.1.3.Final//org.jboss.weld.injection.MethodInvocationStrategy$SpecialParamPlusBeanManagerStrategy.invoke(MethodInvocationStrategy.java:187)
    at org.jboss.weld.core@3.1.3.Final//org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:330)
    at org.jboss.weld.core@3.1.3.Final//org.jboss.weld.event.ExtensionObserverMethodImpl.sendEvent(ExtensionObserverMethodImpl.java:123)
    at org.jboss.weld.core@3.1.3.Final//org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:308)
    at org.jboss.weld.core@3.1.3.Final//org.jboss.weld.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:286)
    at javax.enterprise.api//javax.enterprise.inject.spi.ObserverMethod.notify(ObserverMethod.java:124)
    at org.jboss.weld.core@3.1.3.Final//org.jboss.weld.util.Observers.notify(Observers.java:166)
    at org.jboss.weld.core@3.1.3.Final//org.jboss.weld.event.ObserverNotifier.notifySyncObservers(ObserverNotifier.java:285)
    at org.jboss.weld.core@3.1.3.Final//org.jboss.weld.event.ObserverNotifier.notify(ObserverNotifier.java:273)
    at org.jboss.weld.core@3.1.3.Final//org.jboss.weld.event.ObserverNotifier.fireEvent(ObserverNotifier.java:177)
    at org.jboss.weld.core@3.1.3.Final//org.jboss.weld.event.ObserverNotifier.fireEvent(ObserverNotifier.java:171)
    at org.jboss.weld.core@3.1.3.Final//org.jboss.weld.bootstrap.events.AbstractContainerEvent.fire(AbstractContainerEvent.java:53)
    at org.jboss.weld.core@3.1.3.Final//org.jboss.weld.bootstrap.events.AbstractDefinitionContainerEvent.fire(AbstractDefinitionContainerEvent.java:44)
    at org.jboss.weld.core@3.1.3.Final//org.jboss.weld.bootstrap.events.AfterBeanDiscoveryImpl.fire(AfterBeanDiscoveryImpl.java:75)
    at org.jboss.weld.core@3.1.3.Final//org.jboss.weld.bootstrap.WeldStartup.deployBeans(WeldStartup.java:462)
    at org.jboss.weld.core@3.1.3.Final//org.jboss.weld.bootstrap.WeldBootstrap.deployBeans(WeldBootstrap.java:86)
    at org.jboss.as.weld@19.0.0.Final//org.jboss.as.weld.WeldStartService.start(WeldStartService.java:97)
    at org.jboss.msc@1.4.11.Final//org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1739)
    at org.jboss.msc@1.4.11.Final//org.jboss.msc.service.ServiceControllerImpl$StartTask.execute(ServiceControllerImpl.java:1701)
    at org.jboss.msc@1.4.11.Final//org.jboss.msc.service.ServiceControllerImpl$ControllerTask.run(ServiceControllerImpl.java:1559)
    at org.jboss.threads@2.3.3.Final//org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
    at org.jboss.threads@2.3.3.Final//org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1982)
    at org.jboss.threads@2.3.3.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
    at org.jboss.threads@2.3.3.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1377)
    at java.base/java.lang.Thread.run(Thread.java:834)

The problem here is that our application already defines two beans for MongoTemplate (implements MongoOperations) and all the clients are using Autowired with @Qualifier.

Not sure why it is complaining for a bean of type MongoOperations while all clients are injected with MongoTemplate.

Could it be an issue because of the multiple beans? If yes, shouldn't it should fail at Injection points in client.

mickeymoon
  • 4,820
  • 5
  • 31
  • 56
  • 1
    If there are two or more beans eligible for injection, you get an 'ambiguous' error. So here it seems Weld (CDI) cannot find the annotated beans. Sure they are annotated with CDI annotations? `@AutoWired` is a spring annotation and if you e.g. `@Controller` or `@Service` or whatever Spring used, CDI cannot find the bean. – Kukeltje Jun 15 '20 at 19:48
  • Actually I am trying to understand here is that why it is complaining for a bean for MongoOperations when all my code references are for MongoTemplate. – mickeymoon Jun 15 '20 at 19:59
  • 2
    Then post code in [mcve] flavour... You can state things, but if I would get one Euro for each question asked here where what was stated differed from the code, I could go on holiday to a carribean island ;-) Not saying I don't believe you, but code is worth a thousand words... – Kukeltje Jun 15 '20 at 20:07
  • 1
    It might be that the method that throws the error is a producer that needs somethin generic or whatever... I don't do/use Spring so I have no idea... Checked the code? Oh and please post version info for others to try to help. So they know which source to look in – Kukeltje Jun 15 '20 at 20:09

0 Answers0