2015-10-14 207 views
-2

自动装配接口类我的代码已经这样设置:错误春季

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" /> 

我不知道为什么我得到这个错误,因为我明确指出接口类是在我的上下文中。有谁明白为什么会发生这种情况?

+0

你的类在哪里实现接口?你忘了让类'myHandler'实现接口'ImyHandler'吗? 'public class myHandler implements ImyHandler' – Jesper

+0

'public class myHandler(){}'不能编译。 – atamanroman

+0

你在这里发布的每一行代码都是假的......不管是java,spring还是其他什么......你试图编译任何东西? – Pras

回答

1

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