Skip to content

mapperLocations is overwritten #787

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

Closed
toshawn opened this issue Feb 23, 2023 · 1 comment · Fixed by #816
Closed

mapperLocations is overwritten #787

toshawn opened this issue Feb 23, 2023 · 1 comment · Fixed by #816
Assignees
Labels
enhancement Improve a feature or add a new feature

Comments

@toshawn
Copy link

toshawn commented Feb 23, 2023

@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

@kazuki43zoo kazuki43zoo self-assigned this May 11, 2023
@kazuki43zoo kazuki43zoo added the enhancement Improve a feature or add a new feature label May 11, 2023
@kazuki43zoo kazuki43zoo added this to the 3.0.2 milestone May 11, 2023
@kazuki43zoo kazuki43zoo added the backport to other version Backport to other maintenance version label May 13, 2023
kazuki43zoo added a commit to kazuki43zoo/spring that referenced this issue May 13, 2023
Fixes mybatisgh-787

* addMapperLocations
* addTypeHandlers
* addScriptingLanguageDrivers
* addPlugins
* addTypeAliases
@kazuki43zoo kazuki43zoo removed the backport to other version Backport to other maintenance version label May 13, 2023
@kazuki43zoo kazuki43zoo removed this from the 3.0.2 milestone May 13, 2023
kazuki43zoo added a commit to kazuki43zoo/spring that referenced this issue May 13, 2023
Fixes mybatisgh-787

* addMapperLocations
* addTypeHandlers
* addScriptingLanguageDrivers
* addPlugins
* addTypeAliases

(cherry picked from commit f206e7e)
@kazuki43zoo
Copy link
Member

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improve a feature or add a new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants