Bean定义重写异常:org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name ‘address’ defined in class path resource [com/jbit/SpringConfig.class]
看到了类似的问题,其实这个问题就是重复扫描了。
错误提示:
Caused by: org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name ‘address’ defined in class path resource [com/jbit/SpringConfig.class]: Cannot register bean definition [Root bean: class [null]; scope=; abstract=false; lazyInit=null; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=springConfig; factoryMethodName=address; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [com/jbit/SpringConfig.class]] for bean ‘address’: There is already [Generic bean: class [com.jbit.entity.Address]; scope=singleton; abstract=false; lazyInit=null; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in file [D:\Program\Y2\springboot\springboot02-config\target\classes\com\jbit\entity\Address.class]] bound.
解决方法:
图片:
注意红框处
这个是根据你所报错的问题更改
下我是的示例报错的解决方式
@SpringBootApplication(exclude = {Address.class})
Bean定义重写异常:org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name ‘address’ defined in class path resource [com/jbit/SpringConfig.class]看到了类似的问题,其实这个问题就是重复扫描了。错误提示:Caused by: org.springframework.bean
关于同名
bea
n的注册
问题
,spring和springboot有着不同的处理方式:
spring中如果出现两个同名的
bea
n在注册的时候,并不会报出任何的异常,而是后一个注册的
bea
n会将之前注册的
bea
n覆盖掉,这在启动的时候是没有任何
问题
的;但是在实际运行的过程中可能会发生错误,这时如果想再去弥补,就会发现很难找到这个错误的所在。
但是springboot中并不是如此,springboot中...
正确
解决
org
.
springframework
.
beans
.
factory
.
support
.
Bea
n
Definition
Validation
Exception
Bea
n验证异常的有效
解决
方法
关于同名
bea
n的注册
问题
,spring和springboot有着不同的处理方式:
1、spring中如果出现两个同名的
bea
n在注册的时候,并不会报出任何的异常,而是后一个注册的
bea
n会将之前注册的
bea
n覆盖掉,这在启动的时候是没有任何
问题
的;但是在实际运行的过程中可能会发生错误,这时如果想再去弥补,就会发现很难找到这个错误的所在。
2、但是springboot中并不是如此,springboot中如果出现重名的
bea
n,并不会出现覆盖的
问题
,而是在启动过程中,注册时候直接报出
Bea
nDefinitio
java
.lang.IllegalState
Exception
: Failed to load ApplicationContext
at
org
.
springframework
.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.
java
:132)
at
org
.
springframework
.test.co
Caused
by:
org
.
springframework
.
beans
.
factory
.
support
.
Bea
n
Definition
Overr
ide
Exception
: Invalid
bea
n
今天调代码的时候出现了 如下的错误,经过多方查证,发现原来是eclipse版本的
问题
。异常:
四月 26, 2017 10:54:36 上午
org
.apache.catalina.core.ApplicationContext log
信息: Initializing Spring root WebApplicationContext
2017-04-26 10:54:36,882
在Spring工程里,有一个Car类的
bea
n,Main.
java
主程序,My
Bea
nPostProcessor.
java
是
Bea
n后置处理器。
文件目录结构如下:
Car.
java
1 package com.tt.spring.
beans
.cycle;
3 public class Car {
5 private String ...
org
.
springframework
.
beans
.
factory
.
Bea
nCreation
Exception
导致原因:
target目录下,mapper下的xml文件未包含接口包名
原因分析:
IOC扫描的时候直接扫描
java
文件,如果把配置文件放在
java
目录下是无法扫描到xml的,
可以在Pom中加上
<!-- <resources>-->
//存储注册的俄
Bea
n
Definition
private final Map<String,
Bea
n
Definition
>
bea
n
Definition
Map = new ConcurrentHashMap<String,
Bea
n
Definition
>();
//向IoC容器注册解析的
Bea
nDefiniton
public...
出现
Bea
nCreate
Exception
基本就是配置
Bea
n出
问题
了 下面
caused
by中标红的错误就能看出 其中最重要的原因在于
org
.
springframework
.core.NestedIO
Exception
在接着看
[D:\MyEclipse_work\Test2 Maven Webapp\target\classes\com\liu\mapping\generat...