我可以使用下面的代码在spring中配置多个mybatis数据源。在 mybatis-spring 中使用 java 注释和配置(无 xml)的方法是什么?
public class DataSourceSqlSessionFactory {
private Logger logger = LoggerFactory.getLogger(getClass());
private final static String MYBATIS_CONFIG = "mybatis-config-datasource.xml" ;
public final static String AMDB_ENVIRONMENT_ID = "DB1" ;
public final static String AODB_ENVIRONMENT_ID = "DB2" ;
public SqlSessionFactory getSqlSessionFactory(String environment){
InputStream inputStream = null ;
SqlSessionFactory sqlSessionFactory = null ;
try {
inputStream = Resources.getResourceAsStream(MYBATIS_CONFIG);
sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream , environment);
inputStream.close();
logger.info("Get ["+environment +"] data source connection");
} catch (IOException e) {
logger.error("Get ["+environment +"] data source connection failed, error messages : " + e);
}
return sqlSessionFactory ;
}
}