gpt4 book ai didi

java - DeltaSpike 接口(interface)配置不可注入(inject)

转载 作者:行者123 更新时间:2023-12-01 17:04:51 25 4
gpt4 key购买 nike

我正在关注 DeltaSpike documentation创建绑定(bind)配置属性的可注入(inject)接口(interface)。

@Configuration(prefix = "application.")
public interface AppConfig {

@ConfigProperty(name = "name", evaluateVariables = false)
String getApplicationName();
}

我尝试通过 BeanProvider#getContextualReference 使用它并使用@Inject

@Inject
public Framework(final AppContext context, final BeanManager beanManager, AppConfig app) {
this.appContext = context;
this.beanManager = beanManager;
logger.info("Initialization application with name {}.", app.getApplicationName());
}
Exception in thread "main" org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type AppConfig with qualifiers @Default

我还收到警告:
不满足的依赖关系:没有 bean 与注入(inject)点匹配

我尝试摆弄 beans.xml 文件和 build.gradle 中的依赖项,但无济于事,而且我不确定我做错了什么与文档相比。

有人可以尝试为我指出正确的方向吗?

最佳答案

问题不在于 DeltaSpike,而在于 Weld,即该项目所依赖的 CDI 实现。

该问题是由 Gradle 分别构建 mainresource 引起的,因此首先需要修改资源输出以将它们放在一起。这将资源输出设置到类目录。

sourceSets {
main {
output.resourcesDir = output.classesDirs.singleFile
}

test {
output.resourcesDir = output.classesDirs.singleFile
}
}

然后,使用 Gradle 而不是 IDE 运行应用程序,为此,添加并配置 application 插件。这将创建一个名为 run 的 Gradle 任务。

plugins {
id "application"
id "java"
id "io.spring.dependency-management" version "1.0.9.RELEASE"
}

application {
mainClassName = "org.example.app.Main"
}

如果使用 DeltaSpike 注释,他们可能需要修改 beans.xml 以查找all,而不是annotated

更多信息:
https://discuss.gradle.org/t/application-plugin-run-task-should-first-consolidate-classes-and-resources-folder-or-depend-on-installapp-or-stuff-like-weld-se-wont-work/1248

包含最小 DeltaSpike/Weld/Gradle 项目的存储库:
https://gitlab.com/SethFalco/mini-deltaspike

关于java - DeltaSpike 接口(interface)配置不可注入(inject),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61471768/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com