package com.younike.admin.config;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

@Configuration
@MapperScan("com.younike.*.mapper*")
public class DataSourceConfiguration {
//
    @Autowired
    DataSource dataSource;


//    @Bean
//    public MybatisSqlSessionFactoryBean sqlSessionFactory(
//            @Qualifier("mybatisPlusInterceptor") MybatisPlusInterceptor MybatisPlusInterceptor
//    ) throws Exception {
//        MybatisSqlSessionFactoryBean sessionFactoryBean = new MybatisSqlSessionFactoryBean();
//        sessionFactoryBean.setDataSource(dataSource);
//        // 此处要指定mapper.xml文件所在位置
//        sessionFactoryBean.setMapperLocations(
//                resolveMapperLocations()
//        );
//        Interceptor[] plugins = {MybatisPlusInterceptor};
//        sessionFactoryBean.setPlugins(plugins);
//        // 指定自定义的事务工厂
//        sessionFactoryBean.setTransactionFactory(new MyTransactionsFactory());
//        return sessionFactoryBean;
//    }
//
//
//    public Resource[] resolveMapperLocations() {
//        ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver();
//        List<String> mapperLocations = new ArrayList<>();
//        mapperLocations.add("classpath*:/mapper/*/*Mapper.xml");
//        mapperLocations.add("classpath*:/mapper/*/*/*Mapper.xml");
//        List<Resource> resources = new ArrayList();
//        if (!CollectionUtils.isEmpty(mapperLocations)) {
//            for (String mapperLocation : mapperLocations) {
//                try {
//                    Resource[] mappers = resourceResolver.getResources(mapperLocation);
//                    resources.addAll(Arrays.asList(mappers));
//                } catch (IOException e) {
//                }
//            }
//        }
//
//        return resources.toArray(new Resource[resources.size()]);
//    }





}
