天天看点

Spring的注解@Qualifier作用

举个栗子: 同一个接口被多个类实现

@Service("ServiceImpl1")
public class ServiceImpl1 implements ServiceDemo{

}

@Service("ServiceImpl2")
public class ServiceImpl2 implements ServiceDemo{

}
           

在@Autowired注入时,用@Qualfier指明注入哪一个实现类

@Controller
public class EmployeeInfoControl {
   
    @Autowired
    @Qualifier("ServiceImpl2")
    private ServiceDemo employeeService;
}