一个接口
public interface AServlce{
public ADao getAId(Long id);
}
俩个实现
@Service("service")
public class AImpl implements AServlce{
public ADao getAId(Long id){
return new ADao();
}
}
@Service("service1")
public class AImpl implements AServlce{
public ADao getAId(Long id){
return new ADao();
}
}
调用代码
@Controller
@RequestMapping("/")
public class AControl{
@AutoWired
AServlce aServlce;
@RequestMapping("/")
public void fun(HttpServletRequest request,HttpServletResponse response){
略...
}
}
这样是错误的,该接口不知道映射哪个实现类。所以用到@Qualifier注解。
@Controller
@RequestMapping("/")
public class AControl{
@AutoWired
@Qualifier("service")
AServlce aServlce;
@RequestMapping("/")
public void fun(HttpServletRequest request,HttpServletResponse response){
略...
}
}