我的 ServiceLoader 不想加载我的新服务。我想我已经正确设置了一切。
核心.主要
public class Main {
public static void main(String[] args) {
System.out.println("Before");
Iterator<IService> services = ServiceLoader.load(IService.class).iterator();
while (services.hasNext()) {
IService service = services.next();
System.out.println(service.sayHi());
}
System.out.println("After");
}
}
核心服务.IService
package service;
public interface IService {
String sayHi();
}
DbDataBuilder.builder.DbDataBuilder
package builder;
import service.IService;
public class DbDataBuilder implements IService {
public DbDataBuilder() {
}
public String sayHi() {
return "I am Data Builder";
}
}
META-INF/services/service.Iservice
builder.DbDataBuilder
但是当我运行它时,控制台输出是:
Before
After
我有什么问题吗?