在一个类中注入一个bean对象,提示Autowired members must be defined in valid Spring bean (@Component|@Service|…),它的含义就是:自动注入对象必须定义在有效的spring bean内,也就是说只有本身作为bean的类才能注入其他对象。
报错时如下:
public class CheckoutServiceImpl implements CheckoutService{
@Autowired
private BookService bookService;}
改正后:
@Service
public class CheckoutServiceImpl implements CheckoutService{
@Autowired
private BookService bookService;}