Inside application-context.xml:
<context:component-scan base-package="com.myApp">
<context:exclude-filter type="assignable" expression="com.myApp.MyService"/>
</context:component-scan>
<bean id="myService" class="com.myApp.ExtendedService" />
Inside Main.java:
@SpringBootApplication
@ImportResource(locations = {"classpath:application-context.xml"})
public class Main{
//...
}
Inside ExtendedService:
@Service
public class ExtendedService extends MyService{
//...
}
But when I start, I get Invalid Bean definition because myService is bound error. How to exclude the original MyService?
Exception:
Caused by: org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'myService' defined in URL [file:svc.xml]: Cannot register bean definition [Generic bean: class [com.myApp.ExtendedService]; scope=; abstract=false; lazyInit=false; autowireMode=1; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in URL [file:svc.xml]] for bean 'myService': There is already [Generic bean: class [com.myApp.MyService]; scope=singleton; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in URL [jar:file:/.m2/repository/com/myApp/myLib-1.0.0.jar!/com/myApp/MyService.class]] bound.