I use spring.main.lazy-initialization=true to speed up Spring Boot 2.2.8.RELEASE startup. But I found that, configuration class which are annotated by @Configuration
are not loaded. Is it a feature? I cannot find any information about this. Is there any way I can use to use configuration class after setting beans to lazy initialized?
Comment From: bclozel
How are you assessing that these configuration classes aren't loaded? Maybe you are surprised by an expected behavior here?
In any case a sample application that we can run is necessary here if we want to make progress. Could you provide one please?
Comment From: nilknow
My fault! I haven't debug carefully enough, so I describe my problem wrong.
Now I found that the lazy initialization makes @PostConstruct
annotated method doesn't work. That makes me feel like that the configuration class weren't loaded correctly. So my correct problem is: why @PostConstruct
annotated method doesn't works after lazy-initialization property set to true? The configuration class is just like below:
@Configuration
public class SyMybatisInterceptorConfig {
@Resource
private List<SqlSessionFactory> sqlSessionFactoryList;
@PostConstruct
public void addInterceptor() {
DataAuthInterceptor dataAuthInterceptor = new DataAuthInterceptor();
for (SqlSessionFactory sqlSessionFactory : sqlSessionFactoryList) {
sqlSessionFactory.getConfiguration().addInterceptor(dataAuthInterceptor);
}
}
}
Comment From: nilknow
comment about @PostConstruct
is
The PostConstruct annotation is used on a method that needs to be executed after dependency injection is done to perform any initialization What's so called "after dependency injection". Does it mean after all bean was injected to this configuration or after the configuration class injected as a bean?
Comment From: nilknow
I think I have solve this problem. People can use @Lazy(false)
to annotate such a configuration class to let @PostConstruct
annotated method work