package com.wyz.demo.config;


import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;

import java.io.InputStream;

@Configuration
public class BasicConfig {
    // 提供SqlSession

    @Bean
//    @Scope("prototype")
    public SqlSession sqlSession(){
        try{
            InputStream inputStream = Resources.getResourceAsStream("mybatis-config.xml");
            return new SqlSessionFactoryBuilder().build(inputStream).openSession(true);
        }catch (Exception e){
            return null;
        }
    }

}
