@Qualifier:一个接口或服务有多个实现,如何指定实现类

接口或服务

public interface CacheServiceextends Serializable, K extends Serializable> {    
}
实现类1

@Service("redisCacheService")
public class RedisCacheServiceImpl implements CacheService {
    public RedisCacheServiceImpl() { }  
}
实现类2

@Service("ehCacheService")
public class EhCacheServiceImplextends Serializable, K extends Serializable> implements CacheService, K> {
     public EhCacheServiceImpl() { }  
}

调用:

/**
 * The wrapped Jedis instance.
 */
@Autowired
@Qualifier("redisCacheService")
private CacheService cacheService;
@Qualifier指定了别名为redisCacheService的服务










你可能感兴趣的:(Java)