(re)scanning Mybatis mappers from the filesystem

The Mybatis (3.2) manual describes three ways to configure Mappers as follows: http://mybatis.github.io/spring/mappers.html

Is there any way to extend any of these three procedures so that:

  1. Mapper XML files can be read from outside the classpath (i.e. from a filesystem location)
  2. Mapper XML files can be 'rescanned' for changes that have been made to defined queries since the Application started

Thank you for any advice

Answers


It looks like (1) can be achieved along the lines of:

 @Bean   
    public SqlSessionFactory sqlSessionFactory() throws Exception 
    {     
        SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
        sessionFactory.setMapperLocations(new Resource[]{resource1, resource2});
        sessionFactory.setDataSource(getDataSource());    
        return sessionFactory.getObject();   
    } 

In terms of (2), it seems like this is a much-wanted but unavailable feature in Mybatis. One work-around however is to completely re-create the SqlSession and replace the old one - this effectively picks up any changes made to XML Mappers.

 SqlSession sqlSession = applicationConfiguration.createSqlSessionFactory().openSession();
 sqlSession.selectList(...)

Hope this helps someone.


Need Your Help

How to import posts from wordpress into October CMS

wordpress import octobercms

What would be the way to import posts and pages from a wordpress site into a clean installation of october CMS?

Cannot verify client 3000

ios xcode app-store itunesconnect xcode7

I am using xcode 7.1 and trying to upload my app to the app store directly through xcode. While uploading I am getting a weird error:-