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

Document programmatic configuration of SqlSessionFactoryBean #502

Open
berniegp opened this issue Jul 26, 2020 · 1 comment
Open

Document programmatic configuration of SqlSessionFactoryBean #502

berniegp opened this issue Jul 26, 2020 · 1 comment
Assignees

Comments

@berniegp
Copy link

I was reading the changelog for mybatis-spring-2.0.5 and noticed #458. Since I want to avoid XML configuration files, my usage of SqlSessionFactoryBean looks like this:

@Bean
public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
    var factory = new SqlSessionFactoryBean();
    factory.setDataSource(dataSource);

    // Mapper configuration
    var configuration = new org.apache.ibatis.session.Configuration();
    configuration.setAutoMappingBehavior(AutoMappingBehavior.FULL);
    configuration.setMapUnderscoreToCamelCase(true);
    configuration.setDefaultEnumTypeHandler(CustomEnumTypeHandler.class);
    configuration.getTypeHandlerRegistry().register(LocalDate.class, CustomLocalDateTypeHandler.class);
    factory.setConfiguration(configuration);

    // Register the model classes as type aliases
    factory.setTypeAliasesPackage(MyModel.class.getPackage().getName());

    return factory.getObject();
}

#458 introduced another "layer" of option of the already existing Configuration class for setDefaultEnumTypeHandler. I went back to the documentation and noticed that the possibility of using Java configuration is not explained anywhere. Perhaps this could be added to the documentation? Or is one not supposed to use that api for configuration?

@kazuki43zoo
Copy link
Member

kazuki43zoo commented May 14, 2023

@berniegp
Thank you for your contributing!
We can add the description for configuring an SqlSessionFactoryBean withConfiguration in http://mybatis.org/spring/factorybean.html#setup.

@kazuki43zoo kazuki43zoo added this to the General Backlog milestone May 14, 2023
@kazuki43zoo kazuki43zoo self-assigned this May 14, 2023
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