一个接口

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){

    略...

  }

}

相关文章:

  • 2021-12-17
  • 2022-12-23
  • 2022-01-21
  • 2021-11-12
  • 2022-12-23
  • 2022-12-23
  • 2022-02-02
  • 2022-12-23
猜你喜欢
  • 2021-12-05
  • 2022-12-23
  • 2021-11-28
  • 2022-12-23
  • 2021-09-04
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案