濮阳杆衣贸易有限公司

主頁 > 知識庫 > SSH整合中 hibernate托管給Spring得到SessionFactory

SSH整合中 hibernate托管給Spring得到SessionFactory

熱門標(biāo)簽:山東ai外呼電銷機(jī)器人好用嗎 外呼直播語音系統(tǒng) 地圖標(biāo)注專業(yè)和非專業(yè) 汝南縣地圖標(biāo)注app 福建電銷貓機(jī)器人收費(fèi) 四川正規(guī)外呼系統(tǒng)軟件 甘肅銷售電銷機(jī)器人公司 智能電話機(jī)器人銷售話術(shù) 湖北地圖標(biāo)注公司
prop key="hibernate.current_session_context_class">thread/prop>
然后
Resource resource=new ClassPathResource("/WEB-INF/applicationContext.xml");
BeanFactory factory=new XmlBeanFactory(resource);
SessionFactory sessionFactory = (SessionFactory)factory.getBean("sessionFactory");
就可以得到了
剩下的 不會就回爐吧,我 的 做法是 修改HibernateUtil文件的得到SessionFactory 的方法就 什么都解決了
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
//在hibernate托管給Spring時得到sessionFactory
public class HibernateUtil {
private static final SessionFactory sessionFactory;
static {
try {
Resource resource=new ClassPathResource("/WEB-INF/applicationContext.xml");
BeanFactory factory=new XmlBeanFactory(resource);
sessionFactory = (SessionFactory)factory.getBean("sessionFactory");
} catch (HibernateException ex) {
throw new RuntimeException("Exception building SessionFactory: "
+ ex.getMessage(), ex);
}
}
public static final ThreadLocal session = new ThreadLocal();
public static Session currentSession() throws HibernateException {
Session s = (Session) session.get();
// Open a new Session, if this Thread has none yet
if (s == null) {
s = sessionFactory.openSession();
session.set(s);
}
return s;
}
public static void closeSession() throws HibernateException {
Session s = (Session) session.get();
session.set(null);
if (s != null)
s.close();
}
}
//
當(dāng)hibernate沒有托管給Spring使用這種和傳統(tǒng)方式都可以得到啊
sessionFactory = new Configuration().configure("/WEB-INF/hibernate.cfg.xml")
.buildSessionFactory();
您可能感興趣的文章:
  • 詳解JAVAEE——SSH三大框架整合(spring+struts2+hibernate)
  • SSH框架網(wǎng)上商城項目第1戰(zhàn)之整合Struts2、Hibernate4.3和Spring4.2
  • Spring4整合Hibernate5詳細(xì)步驟
  • spring+hibernate 兩種整合方式配置文件的方法
  • Java框架篇:Spring+SpringMVC+hibernate整合開發(fā)
  • Spring 整合 Hibernate 時啟用二級緩存實例詳解
  • Spring+Hibernate+Struts(SSH)框架整合實戰(zhàn)
  • Spring與Hibernate整合事務(wù)管理的理解
  • Spring MVC+FastJson+hibernate-validator整合的完整實例教程
  • struts+spring+hibernate三個框架的整合
  • Spring和Hibernate的整合操作示例

標(biāo)簽:梅州 白銀 南充 黔東 昌都 臨沂 肇慶 吳忠

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《SSH整合中 hibernate托管給Spring得到SessionFactory》,本文關(guān)鍵詞  SSH,整合,中,hibernate,托管,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《SSH整合中 hibernate托管給Spring得到SessionFactory》相關(guān)的同類信息!
  • 本頁收集關(guān)于SSH整合中 hibernate托管給Spring得到SessionFactory的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    精河县| 垦利县| 西峡县| 海原县| 西城区| 教育| 津南区| 东阿县| 霍州市| 城步| 隆回县| 建湖县| 彰化县| 呈贡县| 九江县| 石楼县| 获嘉县| 芮城县| 宁陵县| 泾川县| 辽宁省| 施甸县| 玛纳斯县| 七台河市| 德清县| 枝江市| 天峨县| 平果县| 连州市| 曲水县| 永州市| 巴东县| 贵溪市| 博湖县| 宁河县| 乐东| 惠州市| 唐山市| 洛宁县| 孟连| 东乌珠穆沁旗|