【发布时间】:2020-12-21 05:27:51
【问题描述】:
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" />
Main.java 内部:
@SpringBootApplication
@ImportResource(locations = {"classpath:application-context.xml"})
public class Main{
//...
}
ExtendedService 内部:
@Service
public class ExtendedService extends MyService{
//...
}
但是当我开始时,我得到 Invalid Bean definition 因为 myService is bound 错误。如何排除原有的MyService?
例外:
原因:org.springframework.beans.factory.support.BeanDefinitionOverrideException:在 URL [file:svc.xml] 中定义的名称为“myService”的 bean 定义无效:无法注册 bean 定义 [通用 bean:类 [com.myApp] .ExtendedService];范围=;摘要=假;懒惰初始化=假;自动线模式=1;依赖检查=0;自动接线候选=真;主要=假;工厂BeanName=空;工厂方法名=空;初始化方法名=空;销毁方法名=空;在 URL [file:svc.xml]] 中为 bean 'myService' 定义:已经有 [Generic bean: class [com.myApp.MyService];范围=单例;摘要=假;懒惰初始化=假;自动线模式=0;依赖检查=0;自动接线候选=真;主要=假;工厂BeanName=空;工厂方法名=空;初始化方法名=空;销毁方法名=空;在 URL [jar:file:/.m2/repository/com/myApp/myLib-1.0.0.jar!/com/myApp/MyService.class]] 中定义。
【问题讨论】: