-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Registering Plugin #7
Comments
This is an example which I use to register a pagination plugin (PageHelper) in pure Java config style. Though looks a bit bored, it's not so unacceptable in terms of the fact that you need to write it only once. @Bean
public SqlSessionFactory sqlSessionFactory(DataSource dataSource)
throws Exception {
SqlSessionFactoryBean sfb = new SqlSessionFactoryBean();
sfb.setDataSource(dataSource);
Properties prop = new Properties();
prop.setProperty("dialect", "mysql");
PageHelper pagePlugin = new PageHelper();
pagePlugin.setProperties(prop);
Interceptor[] plugins = {pagePlugin};
sfb.setPlugins(plugins);
SqlSessionFactory factory = sfb.getObject();
factory.getConfiguration().setMapUnderscoreToCamelCase(true);
return factory;
} |
Thanks. Would have been nice if it was possible to do it by setting something in application.properties instead of overriding the bean creation. |
I am thinking to register all plugins automatically. Let try this approach. PR is welcome :) |
I'll see what I can do this weekend :-) |
Didn't get around to work in it yet. While I'm at it, any idea of the best way to implement the configuration of settings the same way? I've seen liukaitj's example about doing it. Is this the best approach? SqlSessionFactory factory = sfb.getObject();
factory.getConfiguration().setMapUnderscoreToCamelCase(true); instead of using mybatis-config.xml
|
Actually if this works, why need to bring it inside?
The issue with #8 is it does not work by putting it in mybatis-config.xml To quote the PageHelper example in here, I am doing this in mybatis-config.xml and it is working well:
|
As soon as you define mybatis-config.xml in the application.properties file, all other mybatis settings from that file are ignored. |
Is there an easy way to register a Plugin (org.apache.ibatis.plugin.Interceptor) to the sqlSessionFactory with only java configuration?
The text was updated successfully, but these errors were encountered: