最新的spring4怎么跟mybatis集成
2015-03-11
展开全部
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
public class MyBatisUtil {
private final static SqlSessionFactory sqlSessionFactory;
static {
ApplicationContext ac = new FileSystemXmlApplicationContext("classpath:applicationContext.xml");
sqlSessionFactory = (SqlSessionFactory)ac.getBean("sqlSessionFactory");
}
public static SqlSessionFactory getSqlSessionFactory() {
return sqlSessionFactory;
}
}
mybatis 的注解没有提供注入sqlSessionFactory的方法。你可以通过上面的方式获得sqlSessionfanctory
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
public class MyBatisUtil {
private final static SqlSessionFactory sqlSessionFactory;
static {
ApplicationContext ac = new FileSystemXmlApplicationContext("classpath:applicationContext.xml");
sqlSessionFactory = (SqlSessionFactory)ac.getBean("sqlSessionFactory");
}
public static SqlSessionFactory getSqlSessionFactory() {
return sqlSessionFactory;
}
}
mybatis 的注解没有提供注入sqlSessionFactory的方法。你可以通过上面的方式获得sqlSessionfanctory
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询