首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ServiceLoader找不到我的实现

ServiceLoader找不到我的实现
EN

Stack Overflow用户
提问于 2021-06-07 13:01:03
回答 1查看 274关注 0票数 1

我试图在模块系统中使用ServiceLoader,就像将服务提供者作为模块头部署在这里的文档- 点击中一样。

我有以下项目:

模块tester.client

代码语言:javascript
复制
package tester.client;

import tester.common.Showable;

import java.util.ServiceLoader;

public class Main {

    public static void main(String[] args) {
        ServiceLoader<Showable> loader = ServiceLoader.load(Showable.class);
        loader.findFirst().orElseThrow(); //throws Exception
    }

}

module-info.java

代码语言:javascript
复制
import tester.common.Showable;

module tester.client {
    requires tester.common;
    uses Showable;
}

模块tester.common

代码语言:javascript
复制
package tester.common;

public interface Showable {
    void show();
}

module-info.java

代码语言:javascript
复制
module tester.common {
    exports tester.common;
}

模块tester.gui

代码语言:javascript
复制
package tester.gui;

import tester.common.Showable;

public class Window implements Showable {
    @Override
    public void show() {

    }
}

module-info.java

代码语言:javascript
复制
module tester.gui {
    requires tester.common;
    provides tester.common.Showable with tester.gui.Window;
}

问题:

ServiceLoader不加载我的实现。

  • tester.client使用可显示
  • tester.common出口可展示
  • tester.gui提供了可显示的窗口
EN

回答 1

Stack Overflow用户

发布于 2021-06-07 17:22:49

结果发现问题是特定于IDE的。由于我的IDE (Intellij )有自己的附加模块系统,我需要添加tester.gui模块作为tester.client模块的依赖项。

@samabcde提供的解决方案

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67872101

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档