Search code examples
javajakarta-eejava-ee-7quarkus

Why Quarkus doesn't scan JakartaEE beans?


I am working on a migration from a JavaEE/JakartaEE (v. 7.0) application deployed on JBoss to Quarkus.

I've removed all the JEE and JBoss dependencies and replaced them with Quarkus dependencies. Now, when I'm starting the application by using the command: mvn compile quarkus:dev specified in Quarkus documentation, I'm receiving a lot of errors like the following one:

[1] Unsatisfied dependency for type com.freesoft.diba.jeeop.cert_proxy.acme.database.NonceRepository and qualifiers [@Default]
[ERROR]         - java member: com.freesoft.diba.jeeop.cert_proxy.acme.AcmeProtocolFeature#nonceRepository
[ERROR]         - declared on CLASS bean [types=[java.lang.Object, com.freesoft.diba.jeeop.cert_proxy.acme.AcmeProtocolFeature], qualifiers=[@Default, @Any], target=com.freesoft.diba.jeeop.cert_proxy.acme.AcmeProtocolFeature] 

The class AcmeProtocolFeature is the following one:

@Provider
public class AcmeProtocolFeature implements DynamicFeature {

    @Inject
    Logger logger;
    @Inject
    PolicyHandler policyHandler;
    @Inject
    NonceRepository nonceRepository
    [...]

The class NonceRepository is the following one:

public class NonceRepository {

    @Inject
    @PersistenceContext(unitName = "acme")
    EntityManager em;

In the previous version (the JEE one) of the application everything worked just well. I'm wondering why this is not working anymore as expected, because as long as I know, Quarkus implements all JavaEE/JakartaEE standards?!


Solution

  • As it is stated in Quarkus documentation, the classes that are not having a bean defining annotation are not discovered.

    Bean classes that don’t have a bean defining annotation are not discovered. This behavior is defined by CDI. But producer methods and fields and observer methods are discovered even if the declaring class is not annotated with a bean defining annotation (this behavior is different to what is defined in CDI)

    In JavaEE/JakartaEE, if a class did not have specified any bean defining annotation, then the it will be considered by default annotated with @Dependent, so basically, this is why the JavaEE/JakartaEE version of the application worked well, and the Quarkus one did not work at all.

    The solution would be to explicitly specify a bean defining annotation on top of each class that you want to inject further, specifically in this scenario, the class NonceRepository should be annotated at least with the @Dependent annotation.