错误描述:Could not autowire. No beans of 'addUser' type found. less... (Ctrl+F1) Checks autowiring problems in a beanclass
缺少包的扫描,那就添上
<context:component-scan base-package="com.Service"/>
其次还要注意一点:
在base-package指明一个包时:
<context:component-scan base-package="com.Service"/>
表明在这个包及其子包中,如果某个类的头上带有特定的注解
@Component,@Repository,@Service,@Controller,就会将这个对象作为Bean注册进Spring容器。
在<context:component-scan base-package=” ”/>中指定多个包时,多个包用逗号隔开。
其次还有:@Autowired会报错时,尝试用@Resource,两者之间的主要区别:@Autowired默认按类型装配(这个注解是属于Spring的),而@Resource(这个注解属于J2EE的),默认按照名称进行装配。