Skip to content

Failure analysis of NoUniqueBeanDefinitionException reports "defined in null" when bean definition has no resource description #33765

@sergey-morenets

Description

@sergey-morenets

If I try to declare the same class twice as Spring bean and then inject it:

@Component
public class MemoryWriter {}

and

public class AppInitializer implements ApplicationContextInitializer<GenericApplicationContext>{

	@Override
	public void initialize(GenericApplicationContext ctx) {
		ctx.registerBean(MemoryWriter.class);
	}	
}

then Spring Boot prints out an error and that's correct but in the second case it doesn't specify location of the class where bean is declared (just "null"):

Parameter 0 of method server in demo.AppConfig required a single bean, but 2 were found:
	- demo.MemoryWriter: defined in null
	- memoryWriter: defined in file [c:\demo\target\classes\demo\MemoryWriter.class]

Spring Boot: 3.0.1

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions