当前位置: 代码迷 >> J2EE >> 初学s2sh,交付action报错Error Creating SessionFactory
  详细解决方案

初学s2sh,交付action报错Error Creating SessionFactory

热度:592   发布时间:2016-04-22 00:45:22.0
初学s2sh,提交action报错Error Creating SessionFactory
希望大家不要喷我,初学s2sh。必要的包已经导入(目前自己这么认为的),在整合的过程中我把hibernate.cfg.xml删除了,数据源就交给spring的配置文件applicationContext-hibernate.xml管理了,该文件时放在WEB-INF/config目录下,里面的内容是:
XML code
<!--    配置数据源 Hibernate支持  -->    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" >        <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>        <property name="username" value="scott" />        <property name="password" value="tiger" />        <property name="url" value="jdbc:oracle:thin:@192.168.93.150:1521:myorcl" />    </bean>    <!--        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">-->    <bean id="sessionFactory"             class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" >        <property name="dataSource">            <ref bean="dataSource" />        </property>        <property name="hibernateProperties">            <props>                <prop key="hibernate.dialect">                    org.hibernate.dialect.Oracle9Dialect                </prop>                <prop key="hibernate.show_sql">true</prop>                <prop key="hibernate.temp.use_jdbc_metadata_defaults">false</prop>            </props>        </property>        <property name="mappingResources">            <list>                <value>com/neusoft/leehom/model/Emp.hbm.xml</value>                <value>com/neusoft/leehom/model/Dept.hbm.xml</value>            </list>        </property>    </bean>

并且利用myeclipse自动生成pojo和映射文件,其中有一个类HibernateSessionFactory.java,里面有的部分内容是
Java code
private static String CONFIG_FILE_LOCATION = "/config/applicationContext-hibernate.xml" ;    private static final ThreadLocal<Session> threadLocal = new ThreadLocal<Session>();    private  static Configuration configuration = new Configuration();        private static org.hibernate.SessionFactory sessionFactory;    private static String configFile = CONFIG_FILE_LOCATION;    static {        try {            configuration.configure(configFile);            sessionFactory = configuration.buildSessionFactory();        } catch (Exception e) {            System.err                    .println("%%%% Error Creating SessionFactory %%%%");            e.printStackTrace();        }    }

由于把hibernate.cfg.xml删除了,所以在这个类中private static String CONFIG_FILE_LOCATION = "/config/applicationContext-hibernate.xml",原本是“/hibernate.cfg.xml”。
在测试的时候发现报错:
Java code
%%%% Error Creating SessionFactory %%%%org.hibernate.HibernateException: /config/applicationContext-hibernate.xml not found    at org.hibernate.internal.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:173)    at org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:1949)    at org.hibernate.cfg.Configuration.configure(Configuration.java:1930)    at com.neusoft.leehom.dao.HibernateSessionFactory.<clinit>(HibernateSessionFactory.java:30)    at com.neusoft.leehom.dao.BaseHibernateDAO.getSession(BaseHibernateDAO.java:13)    at com.neusoft.leehom.dao.EmpDAO.findAll(EmpDAO.java:122)    at com.neusoft.leehom.service.impl.EmpManagerImpl.queryAll(EmpManagerImpl.java:11)    at com.neusoft.leehom.action.EmpAction.showList(EmpAction.java:14)    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)    at java.lang.reflect.Method.invoke(Unknown Source)    at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:453)    at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:292)    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:255)    at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256)    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)    at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98).......
  相关解决方案