Coder Social home page Coder Social logo

Registering Plugin about spring-boot-starter HOT 7 CLOSED

mybatis avatar mybatis commented on May 18, 2024
Registering Plugin

from spring-boot-starter.

Comments (7)

liukaitj avatar liukaitj commented on May 18, 2024 2

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;
    }

from spring-boot-starter.

patrek avatar patrek commented on May 18, 2024

Thanks.

Would have been nice if it was possible to do it by setting something in application.properties instead of overriding the bean creation.

from spring-boot-starter.

eddumelendez avatar eddumelendez commented on May 18, 2024

I am thinking to register all plugins automatically. Let try this approach. PR is welcome :)

from spring-boot-starter.

patrek avatar patrek commented on May 18, 2024

I'll see what I can do this weekend :-)

from spring-boot-starter.

patrek avatar patrek commented on May 18, 2024

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

    <settings>
        <setting name="mapUnderscoreToCamelCase" value="true"/>
    </settings>

from spring-boot-starter.

mallim avatar mallim commented on May 18, 2024

Actually if this works, why need to bring it inside?

 <settings>
        <setting name="mapUnderscoreToCamelCase" value="true"/>
    </settings>

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:

    <plugins>
        <plugin interceptor="com.github.pagehelper.PageHelper">
            <property name="dialect" value="pagehelper.SqlServer2012Dialect"/>
        </plugin>
    </plugins>

from spring-boot-starter.

patrek avatar patrek commented on May 18, 2024

As soon as you define mybatis-config.xml in the application.properties file, all other mybatis settings from that file are ignored.

from spring-boot-starter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.