Quarkus依赖注入因Gradle Library Module中的bean失败 [英] Quarkus dependency injection failing with bean from Gradle Library Module
问题描述
我正在尝试在我的多模块项目中使用依赖项注入,在该项目中我想从库模块中注入bean.但是,它失败了,因为它找不到该bean.
I´m trying to get dependency injection working in my multi-module project where I want to inject a bean from a library module. However, it´s failing because it cannot find the bean.
项目根 settings.gradle
pluginManagement {
repositories {
mavenLocal()
mavenCentral()
gradlePluginPortal()
}
plugins {
id 'io.quarkus' version "${quarkusPluginVersion}"
}
}
include ':service-module'
include ':library-module'
服务模块 build.gradle
尝试编译以及实现
dependencies {
compile project(":library-module")
// implementation project(":library-module")
}
库模块
import javax.enterprise.context.ApplicationScoped;
@ApplicationScoped
public class LibraryBean {
public void hello() {
System.out.println("Hello");
}
}
服务模块发生注入的地方
@ApplicationScoped
public class Application {
@Inject
LibraryBean libraryBean;
}
Stacktrace
com.mylibrary.LibraryBean和限定词[@Default]-Java成员:com.myservice.Application#LibraryBean-在CLASS bean [types = [com.myservice.Application,java.lang.Object],qualifiers = [@ Default,@Any],上声明,target = com.myservice.Application]
Unsatisfied dependency for type com.mylibrary.LibraryBean and qualifiers [@Default] - java member: com.myservice.Application#LibraryBean - declared on CLASS bean [types=[com.myservice.Application, java.lang.Object], qualifiers=[@Default, @Any], target=com.myservice.Application]
我不确定此问题是否与Quarkus有关,还是CDI和Gradle模块存在的一般问题.
I´m not sure if this issue is Quarkus-related or a general problem that exists with CDI and Gradle modules.
如何使DI跨模块工作?
How can I make the DI working accross modules?
推荐答案
您的库模块中是否有 beans.xml
文件?有关更多信息,请参见此问题/答案: https://stackoverflow.com/a/55513723/742081
Do you have a beans.xml
file in your library module? See this question/answer for more info: https://stackoverflow.com/a/55513723/742081
这篇关于Quarkus依赖注入因Gradle Library Module中的bean失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!