为什么多个实现不允许在 module-info.java 中声明为模块服务?

kri*_*a T 3 java service dependency-injection module

我有一个模块提供接口的两种实现。我收到编译错误“重复的服务条目:org.util.hsm.api.HSMService”。两种实现都属于同一模块。

模块信息.java

module org.util.thales.hsm {
    uses org.util.hsm.api.HSMService;
    provides org.util.hsm.api.HSMService with org.util.hsm.thales.ThalesHSMService;
    provides org.util.hsm.api.HSMService with org.util.hsm.safenet.SafeNetHSMService;
}
Run Code Online (Sandbox Code Playgroud)

kri*_*a T 10

经过多次尝试和错误,我找到了解决方案。

module org.util.thales.hsm {
    uses org.util.hsm.api.HSMService;
    provides org.util.hsm.api.HSMService with org.util.hsm.thales.ThalesHSMService, org.util.hsm.safenet.SafeNetHSMService;
}
Run Code Online (Sandbox Code Playgroud)