<commit_before>package org.focusns.common.dao.mybatis;

import org.springframework.context.ResourceLoaderAware;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternUtils;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;

public class SqlSessionFactoryBean extends org.mybatis.spring.SqlSessionFactoryBean implements ResourceLoaderAware {

    private static final String MAPPER_LOCATION_PATTERN = "classpath*:*/**/*Mapper.xml";

    private String mapperBasePackage;
    //private String mapperLocationPattern = MAPPER_LOCATION_PATTERN;
    private ResourcePatternResolver resourcePatternResolver;


    public void setMapperBasePackage(String mapperBasePackage) {
        this.mapperBasePackage = mapperBasePackage;
    }

    /*public void setMapperLocationPattern(String mapperLocationPattern) {
        this.mapperLocationPattern = mapperLocationPattern;
    }*/

    @Override
    public void setResourceLoader(ResourceLoader resourceLoader) {
        this.resourcePatternResolver = ResourcePatternUtils.getResourcePatternResolver(resourceLoader);
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        //
        Assert.hasText(mapperBasePackage, "Mapper base package can not be null!");
        //
        String mapperLocationPattern = ClassUtils.convertClassNameToResourcePath(mapperBasePackage) + "/**/*Mapper.xml";
        Resource[] mapperLocations = resourcePatternResolver.getResources(mapperLocationPattern);
        Assert.notEmpty(mapperLocations, String.format("Mapper Locations is empty under package %s!", mapperBasePackage));
        //
        super.setMapperLocations(mapperLocations);
        //<commit_msg>解决 SqlSessionFactoryBean 在单元测试中无法扫描到 Mapper 文件的 BUG<commit_after>package org.focusns.common.dao.mybatis;

import org.springframework.context.ResourceLoaderAware;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternUtils;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;

public class SqlSessionFactoryBean extends org.mybatis.spring.SqlSessionFactoryBean implements ResourceLoaderAware {

    private String mapperBasePackage;
    private ResourcePatternResolver resourcePatternResolver;

    public void setMapperBasePackage(String mapperBasePackage) {
        this.mapperBasePackage = mapperBasePackage;
    }

    @Override
    public void setResourceLoader(ResourceLoader resourceLoader) {
        this.resourcePatternResolver = ResourcePatternUtils.getResourcePatternResolver(resourceLoader);
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        //
        Assert.hasText(mapperBasePackage, "Mapper base package can not be null!");
        //
        String mapperLocationPattern = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX +
                ClassUtils.convertClassNameToResourcePath(mapperBasePackage) + "/**/*Mapper.xml";
        Resource[] mapperLocations = resourcePatternResolver.getResources(mapperLocationPattern);
        Assert.notEmpty(mapperLocations, String.format("Mapper Locations is empty under package %s!", mapperBasePackage));
        //
        super.setMapperLocations(mapperLocations);
        //
{'fraction_non_alphanumeric': 0.07870894677236694, 'fraction_numerical': 0.0, 'mean_word_length': 4.670947030497592, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 3}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7255278', 'n_tokens_mistral': 895, 'n_tokens_neox': 886, 'n_words': 168}