@Autowired
@Autowired 注释,它可以对类成员变量、方法及构造函数进行标注,完成自动装配的工作,可以省略getter、setter方法。
@Qualifier
若有多个类实现了ProductService,@Service设置不同参数名
@Qualifier的参数名称必须为我们之前定义@Service注解的名称之一,需要用到哪个就写哪个。
eg.
public class ProductController {
@Autowired
@Qualifier("productService")
private ProductService productService;
}
@Service("productService")
public class ProductServiceImpl implements ProductService {
}
@Service("productService2")
public class ProductServiceImpl2 implements ProductService {
}