Search code examples
javamybatisspring-mybatis

Spring - Mybatis reload fragment from XML


I have a WebApp using JRebel (7) and Spring-Mybatis (1.3.1)

When I change an sql statement inside an XML mapper file while the AppServer (Tomcat 8) is running, the updated SQL does get executed by the framework.

<select ... >

If I change an sql fragment in an XML file, the changes don't get reflected in the query executed, until I restart the Application server.

<sql ... >

Is there a way to reload the Sql fragment from file, either via configuration or Java call?


Solution

  • I found one way...

    In my AppConfig, I scope the bean that provides an SqlSessionFactory with prototype scope - then it re-creates the bean on every request, and caching is broken. This is of course highly inefficient; but it's a nifty work-around on the Developer PC while you're working on an SQL fragment:

    @Bean
    @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
    public SqlSessionFactory sqlSessionFactory() throws Exception {
        ...
    }