tangou

spring @Autowired Could not autowire field解决方法

autowire异常主要由三个情况发生的

像上面的情况是BrandDao没有注入,


1。你的BrandServiceImpl必须以@Service或@Component注解才行。

 @service放到实现上 

2。自动写入的时候把接口写成实现类了 
@Autowired 
private BrandServiceImpl      brandServiceImpl; 
应该是 
@Autowired 
private BrandService    brandService ;

 

3.在BrandDao 类上加上@Repository注解

 


4.在xml中配置扫描路径 

Xml代码  收藏代码
    1. <mvc:annotation-driven />  
    2.     <context:component-scan base-package="com.xxx.service.impl com.xxx.controller"/>  

posted on 2017-08-02 16:45  tangou  阅读(748)  评论(0)    收藏  举报

导航