例如,我有一个在构造函数中获得依赖的类,比如
class ExampleService() {
private Dependency dep;
public ExampleService(Dependency dep) {
this.dep = dep;
}
}
和依赖类:
class Dependency {
public static Dependency getInstance() {
return new Dependency();
}
private Dependency() {
/*constructor implementation here*/
}
}
我想通过 @Inject EJB 注释将 Dependency.getInstance() 方法的结果注入到 ExampleService 构造函数中。可能吗?如何?谢谢你。