Autowire
Posted Mr.yang.localhost
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Autowire相关的知识,希望对你有一定的参考价值。
Field userService in com.demo.web.Controller.HomeController required a single bean, but 2 were found:
- userServiceImpl: defined in file [C:\Users\yangyuping\Desktop\r\maven-projects\web-app\target\classes\com\demo\web\Controller\UserServiceImpl.class]
- IUserService: defined in file [C:\Users\yangyuping\Desktop\r\maven-projects\web-app\target\classes\com\demo\web\Controller\IUserService.class]
一、指定bean名字为 userServiceImpl
@Autowired
private IUserService userServiceImpl;
二、在@Service里指定服务名字
@Service("userService")
public class UserServiceImpl implements IUserService {
@Autowired
private IUserService userService;
以上是关于Autowire的主要内容,如果未能解决你的问题,请参考以下文章
Spring笔记03(创建对象,DI设值注入,自动装配(autowire))
ActiveMQ消息生产者自动注入报错:Could not autowire. No beans of 'JmsMessagingTemplate' type found(示例代码(代