For example, the AOT processing stage reads mapperLocations in mybatisProperties to add hints.resources()
public class MybatisBeanFactoryInitializationAotContribution implements BeanFactoryInitializationAotContribution {
private final MybatisProperties mybatisProperties;
public MybatisBeanFactoryInitializationAotContribution(MybatisProperties mybatisProperties) {
this.mybatisProperties = mybatisProperties;
}
@Override
public void applyTo(GenerationContext generationContext, BeanFactoryInitializationCode beanFactoryInitializationCode) {
log.info("MybatisBeanFactoryInitializationAotContribution {}", mybatisProperties.getMapperLocations());
RuntimeHints hints = generationContext.getRuntimeHints();
String[] mapperLocations = mybatisProperties.getMapperLocations();
if (mapperLocations != null) {
log.info("mapperLocations-{}", mapperLocations);
Stream.of(mapperLocations).map(item -> item.replace("classpath:/", "")).forEach(hints.resources()::registerPattern);
}
}
}
mybatis:
configuration:
map-underscore-to-camel-case: true
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
mapper-locations: classpath:/mapper/*.xml
Comment From: snicoll
@admintertar BeanFactoryInitializationAotContribution runs at build-time during AOT processing. At build-time, we are not instantiating any bean, unless the ones that are preparing the application context.
If you want to rely on this, I suggest to bind the class yourself, something like:
MybatisProperties properties = Binder.get(environment)
.bind("mybatis", Bindable.of(MybatisProperties.class))
.get();
Injecting the environment is fine as it's a core framework concern.
Comment From: admintertar
@admintertar
BeanFactoryInitializationAotContributionruns at build-time during AOT processing. At build-time, we are not instantiating any bean, unless the ones that are preparing the application context.If you want to rely on this, I suggest to bind the class yourself, something like:
java MybatisProperties properties = Binder.get(environment) .bind("mybatis", Bindable.of(MybatisProperties.class)) .get();Injecting the environment is fine as it's a core framework concern.
Thank you very much for your answer! It's very helpful to me.