在Spring中自动装配接口类时出错

时间:2015-10-14 20:11:33

标签: java spring

我的代码设置了这个:

public class myResource() {
   @Autowired
   ImyHandler myHandler;

   ....
}

下一层包含我的处理程序类。我有两组类,一个是接口类,另一个是常规类,如:

public interface myHandler() {
      public myObject modifyFunction();
}

然后我的普通课看起来像:

public class myHandler() {
     ....
}

但是,当我构建项目时,我收到此错误:

Error creating bean with name 'myResource': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: ImyHandler

在我的context-web.xml文件中,我宣布:

<bean id="myHandler" class="myHandler" />

我不确定为什么我会收到此错误,因为我明确声明接口类在我的上下文中。有谁知道为什么会这样?

1 个答案:

答案 0 :(得分:1)

您还需要在bean中指定要创建的类的包。