缺少依赖性错误经常发生

时间:2013-08-07 05:24:50

标签: dependency-injection jersey guice

我使用谷歌guice作为DI框架将我的接口绑定到不同的实现。服务器正常运行,但每当我尝试调用Resource类时,都会发生以下错误。并不是绑定永远不会起作用,但大部分时间它都会失败。我不知道我错过了什么。我在下面给出了一些源代码。

ModuleClass

public class ABCModule extends AbstractModule {
@Override
protected void configure() {
    bind(IConnection.class).to(ABCConnection.class);
}

注入完成的资源类

public class Resource {

Logger log = LoggerFactory.getLogger(Resource.class);
private final IContact contact;
private final IContactFolder contactFolder;

@Inject
public MLContact(IConnection con, IContactFolder contactFolder) {
    this.contact = contact;
    this.con = con;
    this.contactFolder = contactFolder;
   }
   //Resource class methods
    ..
     ......
}

我正在使用guice-3.0.jar

编辑1:

   INFO: Initiating Jersey application, version 'Jersey: 1.17 01/17/2013 04:27 PM'   Aug 8, 2013 9:54:59 AM com.sun.jersey.spi.inject.Errors processErrorMessages
   SEVERE: The following errors and warnings have been detected with resource and/or provider classes:
   SEVERE: Missing dependency for constructor public com.motilink.server.services.MLContact(com.motilink.connector.IContact,com.motilink.connector.IConnection,com.motilink.connector.IContactFolder) at parameter index 0
   SEVERE: Missing dependency for constructor public com.motilink.server.services.MLContact(com.motilink.connector.IContact,com.motilink.connector.IConnection,com.motilink.connector.IContactFolder) at parameter index 1

0 个答案:

没有答案