使用spring 的@Autowired注解引起错误org.springframework.beans.factory.BeanCreationExceptio
我要创建一个springmvc项目,使用了@Autowired注解引起下面的错误
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'clothesController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.clothes.service.ClothesService com.clothes.controller.ClothesController.clothesService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.clothes.service.ClothesService] 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)}
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.clothes.service.ClothesService com.clothes.controller.ClothesController.clothesService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.clothes.service.ClothesService] 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)}
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.clothes.service.ClothesService] 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)}
2014-10-20 8:58:05 org.apache.catalina.core.StandardContext loadOnStartup
严重: Servlet /product threw load() exception
org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.clothes.service.ClothesService] 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)}
意思好像是ClothesService这个无法实例化,导致无法创建clothesController。
@Service("clothesService")
@Transactional
public class ClothesServiceImpl extends CommonServiceImpl implements ClothesService{
}
@Controller
@RequestMapping("/clothesController")
public class ClothesController {
private static final Logger logger=Logger.getLogger(ClothesController.class);
@Autowired
private ClothesService clothesService;
private String message;
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
@RequestMapping(params = "clothes")
public String toMainPage(){
return "main/index";
}
}
网上查资料,说要再配置文件中加
<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
我也加上去了,现在不清楚问题出在哪里了,求解答。