Skip to content

MapperScannerConfigurer cause early initialize bean #452

Closed
@huangxfchn

Description

@huangxfchn

description

Since 2.0.2, MapperScannerConfigurer has changed a lot, but it brings bug.

Mapperscannerconfigurer belongs to beandefinitionregistrypostprocessor. During this period, the bean has not been initialized, but the processpropertyplaceholders() method traverses the entire ApplicationContext, leading to the bean being instantiated in advance, because ApplicationContext.getBeansOfType() will be created in advance by default.

If the bean is instantiated in advance, it will cause some problems, such as unable to rely on injection, failure to get configuration parameters, etc

code

MapperScannerConfigurer.java

public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) {
    if (this.processPropertyPlaceHolders) {
      processPropertyPlaceHolders();
    }
    //……
}

private void processPropertyPlaceHolders() {
	Map<String, PropertyResourceConfigurer> prcs = applicationContext.getBeansOfType(PropertyResourceConfigurer.class);
	//……
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions