Eclipse 整合 Spring4.3 Struts2.5 Hibernate5.3的Maven項目筆記

這裏寫圖片描述

//下面是測試類,僅測試了Dao層

package com.ssh.entity;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;


public class EntityTest {

    private static ApplicationContext context = null;
    SessionFactory sessionFactory = null;


    @Before
    public void init() throws Exception {
        context = new ClassPathXmlApplicationContext("applicationContext.xml");
        sessionFactory = (SessionFactory) context.getBean("mySessionFactory");
    }
    @Test
    public void a() {
        Session s= sessionFactory.openSession();
        System.out.println(s.createQuery("from Goods").list().toString());;
    }


}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章