0
我有以下的包層次
-org.bmark
--dao
---實現
---接口
--services
--- implementation
--- interfaces
這是我的web.xml中春3 IOC註釋
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/ApplicationContext.xml</param-value>
</context-param>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
這是我的applicationContext.xml
<context:annotation-config/>
<context:component-scan base-package="org.bmark.dao"/>
<context:component-scan base-package="org.bmark.services"/>
的一部分,我有一個的UserDAO和ContentTypeDAO(兩者都實現)。我也有一個UserService和一個ContentTypeService(都有實現)。 services類具有@Service註釋。
UserDAO是@Autowired到UserServiceImpl的實現中,並且一切正常。問題是,ContentTypeDAO也@Autowired到ContentTypeServiceImpl但是當我啓動服務器我得到這個異常:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contentTypeServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.bmark.dao.intefaces.ContentTypeDAO org.bmark.services.implementations.ContentTypeServiceImpl.contentTypeDao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.bmark.dao.intefaces.ContentTypeDAO] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}<br/>
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.bmark.dao.intefaces.ContentTypeDAO org.bmark.services.implementations.ContentTypeServiceImpl.contentTypeDao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.bmark.dao.intefaces.ContentTypeDAO] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}<br/>
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.bmark.dao.intefaces.ContentTypeDAO] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
爲什麼我讓我的ContentTypeDAO這個例外,而不是與我的UserDAO得到它? 我該如何解決這個問題?