Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to customize settings using ConfigurationCustomizer/SqlSessionFactoryBeanCustomizer #928

Open
andbin opened this issue Dec 4, 2023 · 0 comments
Assignees

Comments

@andbin
Copy link

andbin commented Dec 4, 2023

Where I work, we have several Spring Boot 3.x applications that use MyBatis through the mybatis-spring-boot-starter (3.0.2) dependency. We would like to “force” some MyBatis settings (like the defaultStatementTimeout) using our core library used by all applications so that each application does not need particular changes (even in the future).

Initially, I thought this task was possible using a custom auto-configuration and some kind of “customizer”. Indeed, I found there are two customizers: ConfigurationCustomizer and SqlSessionFactoryBeanCustomizer.

However, these customizations are not helpful for us. The configuration is not directly explicit in yaml configuration file since each application uses the config-location property, and thus, ConfigurationCustomizers are never fired (even if present). SqlSessionFactoryBeanCustomizers are fired, but the configuration is still null, so there is no easy/clean way to force some settings, as I said before.

I understand things are not currently this way, but I believe the firing of ConfigurationCustomizers is really misplaced. In theory, it should be done just before the line:

return this.sqlSessionFactoryBuilder.build(targetConfiguration);

(see buildSqlSessionFactory() in SqlSessionFactoryBean)

Because, at that point, targetConfiguration is undoubtedly present as a) explicit configuration, b) loaded from XML, or c) defaulted from Configuration constructor.

P.S. I know and understand that currently, SqlSessionFactoryBean is in mybatis-spring while customizers are in mybatis-spring-boot-autoconfigure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants