mybatis / spring

Spring integration for MyBatis 3

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

mapperLocations is overwritten

shawncny opened this issue · comments

commented
@Bean
public SqlSessionFactoryBeanCustomizer sqlSessionFactoryBeanCustomizer1(){
    return factoryBean -> {
        try {
            ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
            Resource[] resources = resolver.getResources("classpath:mapper1/*.xml");
            factoryBean.setMapperLocations(resources);
        } catch (IOException e) {
            e.printStackTrace();
        }
    };
}
@Bean
    public SqlSessionFactoryBeanCustomizer sqlSessionFactoryBeanCustomizer2(){
        return factoryBean -> {
            try {
                ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
                Resource[] resources = resolver.getResources("classpath:mapper2/*.xml");
                factoryBean.setMapperLocations(resources);
            } catch (IOException e) {
                e.printStackTrace();
            }
        };
    }

If I assign values to the mapperLocations property of SqlSessionFactoryBean multiple times, the overwrite problem will occur because:

 public void setMapperLocations(Resource... mapperLocations) {
    this.mapperLocations = mapperLocations;
  }

The setMapperLocations method directly assigns parameters to member properties instead of merging

@uxfix

Thanks for your contributing! I fixed via gh-816(for 3.0.2) and gh-817(for 2.1.1).
You can append mapper xml resources using addMapperLocations instead of setMapperLocation.