spring+mybatis,如何在程序中获得当前sqlsessionfactory

spring+mybatis,如何在程序中获得当前sqlsessionfactory

http://blog.csdn.net/lemonyfei/article/details/8925325

在程序中通过spring来获得sqlSessionFactory

SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
SqlSessionFactory sessionFactory = factoryBean.getObject();

方式有挺多的,因为具体不知道你是怎么搭建的,不太好跟你说。
推荐两个博客你看下,上边介绍的挺详细的。

http://blog.csdn.net/lemonyfei/article/details/8925344

http://fhd001.iteye.com/blog/1121189

一般它都是在xml中配置好了

  <!-- 配置Mybatis的文件 ,mapperLocations配置**Mapper.xml文件位置,configLocation配置mybatis-config文件位置-->  
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">  
        <property name="dataSource" ref="dataSource" />  
        <property name="mapperLocations" value="classpath*:com/lin/mapper/**/*.xml"/>    
        <property name="configLocation" value="classpath:mybatis/mybatis-config.xml" />  
        <!-- <property name="typeAliasesPackage" value="com.tiantian.ckeditor.model"   
            /> -->  
    </bean>  

然后你如果要用直接使用注解就可以了
比如
@Resoure
private SqlSessionFactory sqlSessionFactory
Spirng就会自动给你装配上

http://www.cnblogs.com/hzhuxin/p/3349836.html