67,542
社区成员
发帖
与我相关
我的任务
分享
public interface AccountService {
public List<Account> findAll();
}
@Service("accountService")
public class AccountServiceImpl implements AccountService {
@Autowired
AccountDao accountDao;
@Override
public List<Account> findAll() {
System.out.println("业务层,查询所有账户信息。。。");
return accountDao.findAll();
}
}
@Controller
@RequestMapping("/account")
public class AccountController {
@Autowired
private AccountServiceImpl accountService1;
@RequestMapping("/findAll")
public String findAll(){
System.out.println("表现层--AccountController.findAll()");
List<Account> list = accountService1.findAll();
for(Account a:list){
System.out.println(a);
}
return "success";
}
}
@Autowired
private AccountService accountService1;
@Autowired
private AccountService accountService
@Autowired会自动进行类型匹配,但是你指定了bean的名称,需要再加上@Qualifier注解并指定名称就行了,或者直接加一个@Resources注解指定名称就行了,至于为什么找不到,仔细去看一下@Autowired是怎么进行匹配的就知道了