Java SE Apache DeltaSpike:类型存储库的不满足依赖项

Java SE + Apache DeltaSpike: Unsatisfied dependencies for type Repository

我正在尝试将 DeltaSpike 数据模块与 Weld 一起使用,但每个使用 @Repository 注释的类在我的 IDE 中都会显示警告,并且在运行时会出现异常。

我已多次尝试遵循 DeltaSpike 文档、查看 Baeldung 以及各种文章/论坛,但没有找到解决方案。

有谁知道我可能缺少什么以允许正确注入存储库?

IDE 警告

1
Managed Bean must be a concrete class or @Decorator

运行时异常

1
2
org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type ExampleRepo with qualifiers @Default
  at injection point [BackedAnnotatedParameter] Parameter 1 of [BackedAnnotatedConstructor] @Inject public com.example.myapp.services.ExampleService(ExampleRepo)

示例存储库

1
2
3
4
5
6
7
8
9
10
11
12
13
@Repository(forEntity = Data.class)
public interface ExampleRepo extends EntityRepository<Example, Long> {

    Data findExampleById(long id);

    @Modifying
    @Query("UPDATE Data AS e SET e.locale = ?1 WHERE e.id = ?2")
    int updateLocale(final Locale locale, final long id);

    @Modifying
    @Query("UPDATE Data AS g SET g.reactTranslation = ?1 WHERE g.id = ?2")
    int updateReactTranslation(final boolean toggle, final long id);
}

摇篮

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
plugins {
    id"io.spring.dependency-management" version"1.0.8.RELEASE"
}

ext {
    deltaSpikeVersion ="1.9.2"
}

dependencies {
    // DeltaSpike Extensions
    implementation"org.apache.deltaspike.modules:deltaspike-data-module-api:${deltaSpikeVersion}"
    runtimeOnly"org.apache.deltaspike.modules:deltaspike-data-module-impl:${deltaSpikeVersion}"
    implementation"org.apache.deltaspike.modules:deltaspike-scheduler-module-api:${deltaSpikeVersion}"
    runtimeOnly"org.apache.deltaspike.modules:deltaspike-scheduler-module-impl:${deltaSpikeVersion}"

    // Database
    implementation"org.hibernate:hibernate-core:${hibernateVersion}"
    implementation"org.hibernate:hibernate-c3p0:${hibernateVersion}"
    runtimeOnly"mysql:mysql-connector-java:8.0.18"
}

dependencyManagement {
    imports {
        mavenBom"org.apache.deltaspike.distribution:distributions-bom:${deltaSpikeVersion}"
    }
}

为了澄清,以下也是项目的隐式依赖。

  • org.apache.deltaspike.core:deltaspike-core-api:1.9.2
  • javax.enterprise:cdi-api:2.0
  • org.jboss.weld.se:weld-se-core:3.1.3.Final

我错过了一条 Java SE 特定指令:
https://deltaspike.apache.org/documentation/cdiimp.html#javase6

我不得不使用 DeltaSpike 的 CdiContainer 而不是 Weld 的 SeContainer

1
2
3
4
dependencies {
    implementation"org.apache.deltaspike.cdictrl:deltaspike-cdictrl-api:${deltaSpikeVersion}"
    runtimeOnly"org.apache.deltaspike.cdictrl:deltaspike-cdictrl-weld:${deltaSpikeVersion}"
}