Recently, I've discovered the MVC Toolbox for Jakarta MVC. I decided to give it a try. So I'm developing an application with MVC and the Toolbox. I'm packaging the application as an EAR and aiming to deploy it in OpenLiberty. Following this advice, I tried to disable implicit bean scanning for CDI in the hope of improving OpenLiberty startup time.
Unfortunately, this seems not to work. OpenLiberty fails to start the application, saying
[ERROR ] CWWKZ0106E: Could not start web application polly.
[ERROR ] CWWKZ0002E: An exception occurred while starting the application polly. The exception message was: com.ibm.ws.container.service.state.StateChangeException: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type MvcContext with qualifiers @Default
at injection point [BackedAnnotatedParameter] Parameter 1 of [BackedAnnotatedMethod] @Produces @DefaultTranslationResolver @ApplicationScoped public de.chkal.mvctoolbox.core.translation.DefaultTranslationResolverFactory.getDefaultTranslationResolver(MvcContext)
at de.chkal.mvctoolbox.core.translation.DefaultTranslationResolverFactory.getDefaultTranslationResolver(DefaultTranslationResolverFactory.java:0)
The error message suggests there's something wrong in the way the Toolbox' DefaultTranslationResolverFactory
class lookups the MvcContext
from Jakarta MVC. I've tried annotating the method argument with @Named("mvc")
- to no avail. I've also tried adding a beans.xml to Krazo (the MVC reference implementation), but that resulted in a Weld error about duplicate bean definitions for the MvcContext
bean.
Disclaimer: I'm far from an expert in CDI or in Enterprise Archives, so maybe the construction of my EAR just doesn't make sense. I'd love to learn what could be the culprit in that case.
Any idea what could be going wrong here, or where a potential bug could reside?
I think the reason is the library you are using. It does not find the producer of MvcContext, because it only produces a named
@Named("mvc")
in an archive without abeans.xml
file (krazo-core). This is exactly the expected behaviour fromenableImplizitBeanArchives=false
.To fix this:
Example PR: https://github.com/mthmulders/polly/pull/21
Suggested fix: Ask the framework to ship a beans.xml, see https://struberg.wordpress.com/2019/04/08/to-beans-or-not-to-beans-xml/.