Given that I have a Spring bean configured as
@Service("myService")
public class DefaultService extends MyService {
}
and class using this bean
public class Consumer {
@Autowired
@Qualifier("myService")
private MyService service;
...
}
Now I want my project, including the previous classes, to have the Consumerfollowing implementation MyService. So I would like to rewrite beanMyService
@Service("myService")
public class SpecializedService implements MyService {
}
resulting in Consumertransferring the instance SpecializedServiceinstead DefaultService. By definition, I cannot have two beans with the same name in a Spring container. How can I tell spring that the definition of a new service should rewrite the older one? I do not want to change the class Consumer.
source
share