0

我正在开发一个 API(后端项目),它使用一些包含共享源代码的公共/共享库。所以,我正在开发一个将添加到我们所有后端的功能,这都是我的上下文。

此 API 基于 Jersey 2.x、Jackson、CDI 1.2、JPA、Hibernate 等,配置为部署在 Weblogic 12c 上,并且该项目是使用 Maven 创建的。

所以,我正在研究一个简单的案例:我在适当的公共库 (ref-common) 中创建了一个“接口”(以确保我们的 API 实现相同的接口)并在 API 中创建了实现(war)。

界面(位于库中):

package be.company.ref.common.properties;

public interface ApplicationProperties {

    ...
}

实现(位于战争中):

package be.company.ref.appname.config;

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

public class ApplicationPropertiesImpl implements ApplicationProperties {
    ...
}

第二次,我创建了一种基于 dropwizard 的 healthCheck,它将被我们所有的 API(位于库中)使用:

    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 {
        ...
    }
}

配置(位于 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);
    }
}

部署 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

API 的 pom.xml 提取(ref-common 包含接口和运行状况检查):

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

基本上,API 与共享库一起打包并部署在 weblo 上。

考虑到,我在没有@nnotation 的情况下发布了“ApplicationPropertiesImpl”,因为我尝试了@ApplicationScope 和@Singleton,但是因为两者都不起作用,所以我尝试了没有任何@annotation。

那么,您能否解释一下为什么在部署 API 时会出现此错误,因为我不明白我的错误。

提前致谢。

4

0 回答 0