0

I'm working on an API (backend project) which uses some common/shared libraries containing the shared source codes. So, I'm working on a feature which will be added into all of ours backends, that's all for my context.

This API is based on Jersey 2.x, Jackson, CDI 1.2, JPA, Hibernate etc , configured to be deployed on Weblogic 12c and the project had been created with Maven.

So, I'm working on a simple case: I created an "Interface" into appropriate common library (ref-common) (to be sure ours API implements the same interface) and into the API, I created the implementation (war).

THE interface (located into the library):

package be.company.ref.common.properties;

public interface ApplicationProperties {

    ...
}

The implementation (located into the war):

package be.company.ref.appname.config;

import be.company.ref.common.properties.ApplicationProperties;
i...

public class ApplicationPropertiesImpl implements ApplicationProperties {
    ...
}

In a second time, I created a kind of healthCheck based on dropwizard which will be used by all of ours APIs (located into the library):

    package be.company.ref.common.healthcheck;

import be.company.ref.common.properties.ApplicationProperties;
import com.codahale.metrics.health.HealthCheck;
i...

/**
 * Performs a health check of an API.
 */
@ApplicationScoped
public class NomenclatureApiHealthCheck extends HealthCheck {

    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(NomenclatureApiHealthCheck.class);
    private WebTarget esbClient;
    private String serviceUrl;
    private static final String url = "/healthcheck";

    NomenclatureApiHealthCheck() {
    
    }

    @Inject
    NomenclatureApiHealthCheck(WebTarget esbClient, ApplicationProperties properties) {
        this.esbClient = esbClient;
        this.serviceUrl = properties.getServiceUrlNom();
    }


    @Override
    protected Result check() throws Exception {
        ...
    }
}

The configuration (located into the API):

package be.company.ref.appname.config;

import be.company.ref.common.healthcheck.DatabaseHealthCheck;
import be.company.ref.common.healthcheck.NomenclatureApiHealthCheck;
import com.codahale.metrics.health.HealthCheckRegistry;

import javax.annotation.PostConstruct;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.inject.Inject;

@Startup
@Singleton
public class HealthCheckConfiguration {
        
    @Inject
    HealthCheckRegistry registry;
        
    @Inject
    DatabaseHealthCheck databaseHealthCheck;
        
    @Inject
    NomenclatureApiHealthCheck nomenclatureApiHealthCheck;
        
    @PostConstruct
    public void configure() {
        registry.register(ComponentNames.DATABASE_APPNAME.name(), databaseHealthCheck);
        registry.register(ComponentNames.NOMENCLATURE_API.name(), nomenclatureApiHealthCheck);
    }
}

My issue occurs when I deploy the API:

    25-sept.-2020 16 h 13 min 39 s,SSS CEST> <Error> <Deployer> <BEA-149231> <Unable to set the activation state to true for the application "ref-dimeco-front_war".
weblogic.management.DeploymentException: CDI deployment failure:WELD-001408: Unsatisfied dependencies for type ApplicationProperties with qualifiers @Default
  at injection point [BackedAnnotatedParameter] Parameter 2 of [BackedAnnotatedConstructor] @Inject be.company.ref.common.healthcheck.NomenclatureApiHealthCheck(WebTarget, ApplicationProperties)
  at be.company.ref.common.healthcheck.NomenclatureApiHealthCheck.<init>(NomenclatureApiHealthCheck.java:28)

    at com.oracle.injection.integration.CDIAppDeploymentExtension.initCdi(CDIAppDeploymentExtension.java:95)
    at com.oracle.injection.integration.CDIAppDeploymentExtension.activate(CDIAppDeploymentExtension.java:43)
    at weblogic.application.internal.flow.AppDeploymentExtensionFlow.activate(AppDeploymentExtensionFlow.java:39)
    at weblogic.application.internal.BaseDeployment$2.next(BaseDeployment.java:752)
    at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:45)
    Truncated. see log file for complete stacktrace
Caused By: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type ApplicationProperties with qualifiers @Default
  at injection point [BackedAnnotatedParameter] Parameter 2 of [BackedAnnotatedConstructor] @Inject be.company.ref.common.healthcheck.NomenclatureApiHealthCheck(WebTarget, ApplicationProperties)
  at be.company.ref.common.healthcheck.NomenclatureApiHealthCheck.<init>(NomenclatureApiHealthCheck.java:28)

    at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:359)
    at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:281)
    at org.jboss.weld.bootstrap.Validator.validateGeneralBean(Validator.java:134)
    at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:155)
    at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:518)
    Truncated. see log file for complete stacktrace

Extract of the pom.xml of the API (ref-common contains the interface and the healthcheck):

<dependency>
    <groupId>be.company.ref.common</groupId>
    <artifactId>ref-common</artifactId>
    <version>${ref-common.version}</version>
</dependency>

Basically, The API is packaged with the shared library and deployed on weblo.

Take in account, I posted the "ApplicationPropertiesImpl" without @nnotation because I tried @ApplicationScope and @Singleton but because neither work, I tried without any @annotation.

So, could you explain why this error occurs when I deploy my API because I don't understand my error.

Thanks in advance.

Manucci
  • 1
  • 4
  • 1
    What is your bean discovery mechanism? Look at `META-INF/beans.xml` and see if there is a `bean-discovery-mode` attribute in there. Depending on the answer I can answer your question. My _guess_ in the absence of this information is that the bean discovery mode is `annotated` and you have no bean-defining annotations on your `ApplicationPropertiesImpl` class (i.e. CDI doesn't "know" about it). – Laird Nelson Sep 25 '20 at 16:03
  • the discovery mode is all (bean-discovery-mode="all"). and I tried to annotate "ApplicationPropertiesImpl" with "@Singleton", after that I tried with @ApplicationScope but I got the same issue. – Manucci Sep 26 '20 at 00:34
  • OK, the whole point of bean-discovery-mode of all is that you don't need annotations. Where is your `META-INF/beans.xml` located? That classpath resource identifies a classpath root to be scanned. I'm guessing now that for whatever reason it's not being found. – Laird Nelson Sep 26 '20 at 03:09
  • the xml file is located into webapp/WEB-INF/beans.xml of the API project and there is no beans defined into (for your info). – Manucci Sep 28 '20 at 06:47
  • Your ref-common project (where I presume is located your ApplicationPropertiesImpl) should have a beans.xml file under META-INF, because your maven building project adds it as a jar (not as a war overlay). – Paulo Araújo Sep 28 '20 at 12:25
  • @Paulo, ref-common project has its own beans.xml located into resources/META-INF and the discovery mode is all also. Take in account the ApplicationProperties interface is located into the ref-common project and the implementation is located into the API. – Manucci Sep 28 '20 at 12:39

0 Answers0