spring 中bean注入问题

spring 中bean注入问题
No qualifying bean of type ‘programmer.service.impl.userServiceImpl’ available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

报个这错误我找了半天,以为是自己的bean没有被自动注入,后面才发现是web.xml中没有配置spring的信息

<context-param>
	<param-name>contextConfigLocation</param-name>
	<param-value>classpath:config/spring/applicationContext.xml</param-value>
</context-param> 
还有可能是以下原因

1.该bean所在包未被spring扫描,无法注入该bean,可检查spring配置文件,加入包扫描路径;
2.对应要注入的实现类没有加注解,dao层 @Repository,service层 @Service;
3.service和Impl没有放在同一个包下,导致spring扫描的时候没有扫描Impl包;

发布了5 篇原创文章 · 获赞 2 · 访问量 253

猜你喜欢

转载自blog.csdn.net/qflyIT/article/details/98749951
今日推荐