Several methods for Spring Boot to control bean loading order

@DependsOn

Effect: lliBeanIn lakerBeanprior instantiation

@DependsOn({
    
    "lliBean"}) // 名称必须写对,必须是容器里存在的Bean
@Controller
public class lakerBean {
    
    
	...
}

@Controller
public class lliBean {
    
    
	...
}

@Lazy

Effect: it will be instantiated only when it is accessed for the first time

@AutoConfigureAfter或@AutoConfigureBefore

lakerConfIn lliConfafter loading

@Configuration
@AutoConfigureAfter(lliConf.class)
public class lakerConf
{
    
    
}
@Configuration
public class lliConf
{
    
    
}

Guess you like

Origin blog.csdn.net/abu935009066/article/details/115184253