0

我使用 arquillian 为 payara 项目编写集成测试并使用嵌入式启动器,但 @ConfigProperty 在启动时失败并显示消息。

SEVERE: Exception during lifecycle processing
org.glassfish.deployment.common.DeploymentException: CDI deployment failure:WELD-001408: Unsatisfied dependencies for type String with qualifiers @ConfigProperty
  at injection point [BackedAnnotatedField] @Inject @ConfigProperty private base.config.Config.technicalUser
base.config.Config.technicalUser(Config.java:0)
WELD-001475: The following beans match by type, but none have matching qualifiers:
  - Producer Method [String] with qualifiers [@BatchProperty @Any] declared as [[UnbackedAnnotatedMethod] @Produces @Dependent @BatchProperty public com.ibm.jbatch.container.cdi.BatchProducerBean.produceProperty(InjectionPoint)],
  - Producer Method [String] with qualifiers [@JaxRsParamQualifier @Any] declared as [[UnbackedAnnotatedMethod] @Produces @JaxRsParamQualifier public org.glassfish.jersey.ext.cdi1x.internal.CdiComponentProvider$JaxRsParamProducer.getParameterValue(InjectionPoint, BeanManager)]

注释在类 Config 中。

@Singleton
@Startup
@Data
@Log
public class Config {


    @Inject
    @ConfigProperty(name="PROFILE")
    private String profile;

    @Inject
    @ConfigProperty(name="MICROSERVICE_USER", defaultValue = "admin")
    private String technicalUser;

我试图通过添加一个环境变量来解决这个问题,该环境变量应该在服务的 docker-compose 环境部分中设置,方法是 addEnvironmentVars() 用 @BeforeDeployment 注释,以便将 configProperty 的值放在 Arquillian 环境中,但仍然面临运行集成测试时的错误。

@RunWith(Arquillian.class)
public class ResourceIT extends IntegrationTestBase {

    @Before
    public void setUp() {
        WireMock.reset();
    }

    @BeforeDeployment
    public void addEnvironmentVars() {
        System.setProperty("MICROSERVICE_USER", "value");
    }
4

0 回答 0