HibernateException:Unable to locate config file:e:\\pro.xml

在运行:wiring your web application with open source java时,如果不按照说明中的用hibernate2.1.2,比如:用2.1.8,就会出现文中的问题。

转帖:转自:http://spring.jactiongroup.net/viewtopic.php?t=940&highlight=.HibernateException%3A+Unable+to+locate+config+file

--------------------------------------------------------------------------------

 

软件环境:

struts+hibernate+spring

配置文件:

/WEB-INF/web.xml

引用:

..................

<context-param>

<param-name>contextConfigLocation</param-name>

<param-value>

/WEB-INF/applicationContext-hibernate.xml

</param-value>

</context-param>

<servlet>

<servlet-name>SpringContextServlet</servlet-name>

<servlet-class>

org.springframework.web.context.ContextLoaderServlet

</servlet-class>

<load-on-startup>2</load-on-startup>

</servlet>

.............

 

/WEB-INF/applicationContext-hibernate.xml

引用:

<beans>

<!-- ========================= Start of PERSISTENCE DEFINITIONS ========================= -->

<!-- Choose the dialect that matches your "dataSource" definition -->

<bean id="mySessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean">

<property name="mappingResources">

<list>

<value>com/hibernate/po/TbQueue.hbm.xml</value>

<value>com/hibernate/po/TMsgHistory.hbm.xml</value>

<value>com/hibernate/po/TbHistory.hbm.xml</value>

</list>

</property>

<property name="hibernateProperties">

<props>

<prop key="hibernate.dialect">net.sf.hibernate.dialect.SQLServerDialect</prop>

<prop key="hibernate.show_sql">true</prop>

<prop key="connection.useUnicode">true</prop>

<prop key="connection.characterEncoding">GBK</prop>

<prop key="hibernate.cglib.use_reflection_optimizer">true</prop>

<prop key="hibernate.proxool.xml">e:\\pro.xml</prop>

<prop key="hibernate.proxool.pool_alias">spring</prop>

</props>

</property>

</bean>

<!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->

<bean id="myTransactionManager" class="org.springframework.orm.hibernate.HibernateTransactionManager">

<property name="sessionFactory"><ref local="mySessionFactory"/></property>

</bean>

<!-- Add more services here -->

<!-- CommonService-->

<bean id="commonService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">

<property name="transactionManager"><ref local="myTransactionManager"/></property>

<property name="target"><ref local="commonServiceTarget"/></property>

<property name="transactionAttributes">

<props>

<prop key="find*">PROPAGATION_REQUIRED,readOnly,-DataAccessException</prop>

<prop key="save*">PROPAGATION_REQUIRED,-DataAccessException</prop>

<prop key="del*">PROPAGATION_REQUIRED,-DataAccessException</prop>

<prop key="update*">PROPAGATION_REQUIRED,-DataAccessException</prop>

<prop key="list*">PROPAGATION_REQUIRED,-DataAccessException</prop>

</props>

</property>

</bean>

<bean id="commonServiceTarget" class="org.common.spring.CommonServiceImpl">

<property name="hibernateDAO"><ref local="hibernateDAO"/></property>

</bean>

<!-- DAO定义区 -->

<bean id="hibernateDAO" class="org.common.hibernate.HibernateDAOImpl">

<property name="sessionFactory"><ref local="mySessionFactory"/></property>

</bean>

</beans>

 

e:\pro.xml

引用:

<proxool>

<alias>spring</alias>

<driver-url>jdbc:jtds:sqlserver://127.0.0.1/test;TDS=8.0</driver-url>

<driver-class>net.sourceforge.jtds.jdbc.Driver</driver-class>

<driver-properties>

<property name="user" value="sa" />

<property name="password" value="" />

</driver-properties>

<minimum-connection-count>2</minimum-connection-count>

<maximum-connection-count>20</maximum-connection-count>

<maximum-connection-lifetime>18000000</maximum-connection-lifetime> <!-- 5 hours -->

<house-keeping-test-sql>values(current TimeStamp)</house-keeping-test-sql>

<statistics>1m,15m,1d</statistics>

<statistics-log-level>INFO</statistics-log-level>

<fatal-sql-exception>Connection is closed,SQLSTATE=08003,Error opening socket. SQLSTATE=08S01,SQLSTATE=08S01</fatal-sql-exception>

<fatal-sql-exception-wrapper-class>org.logicalcobwebs.proxool.FatalRuntimeException</fatal-sql-exception-wrapper-class>

<verbose>false</verbose>

</proxool>

 

BaseAction.java

引用:

public abstract class BaseAction extends org.apache.struts.action.Action {

private CommonService commonService;

public void setServlet(ActionServlet actionServlet) {

super.setServlet(actionServlet);

ServletContext servletContext = actionServlet.getServletContext();

WebApplicationContext wac = WebApplicationContextUtils

.getRequiredWebApplicationContext(servletContext);

this.commonService=(CommonService)wac.getBean("commonService");

}

public CommonService getCommonService() {

return commonService;

}

}

 

在服务器启动时报错,信息如下:

引用:

信息: Installing web application at context path /phoneMsg from URL file:F:\tomcat\webapps\phoneMsg

2004-10-26 18:29:19,750 FATAL net.sf.hibernate.util.ConfigHelper - Unable to locate config file: e:\\pro.xml

2004-10-26 18:29:19,781 ERROR org.springframework.web.context.ContextLoader - Context initialization failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mySessionFactory' defined in resource [/WEB-INF/applicationContext-hibernate.xml] of ServletContext: Initialization of bean failed; nested exception is net.sf.hibernate.HibernateException: Unable to locate config file: e:\\pro.xml

net.sf.hibernate.HibernateException: Unable to locate config file: e:\\pro.xml

at net.sf.hibernate.util.ConfigHelper.getConfigStream(ConfigHelper.java:83)

at net.sf.hibernate.util.ConfigHelper.getConfigStreamReader(ConfigHelper.java:104)

at net.sf.hibernate.connection.ProxoolConnectionProvider.configure(ProxoolConnectionProvider.java:122)

at net.sf.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:83)

at net.sf.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:65)

at net.sf.hibernate.cfg.Configuration.buildSettings(Configuration.java:1155)

 

pro.xml的确在E盘啊???

 

返回页首      

 

 

chinalyc

spring 爱好者

注册时间: 2004-02-16

帖子: 6

来自: 北京

 发表于: Fri Nov 05, 2004 9:45 am    发表主题:   

--------------------------------------------------------------------------------

 

在net.sf.hibernate.util.ConfigHelper类中它是这样取先取一个文件的url。

代码:

final URL url = ConfigHelper.locateConfig(path);

public static final URL locateConfig(final String path) {

      try {

         return new URL(path);

      }

      catch(MalformedURLException e) {

                                               

         return findAsResource(path);

      }

   }

   public static final URL findAsResource(final String path) {

      URL url = null;

      // First, try to locate this resource through the current

      // context classloader.

      url = Thread.currentThread().getContextClassLoader().getResource(path);

      if (url != null)

         return url;

      // Next, try to locate this resource through this class's classloader

      url = ConfigHelper.class.getClassLoader().getResource(path);

      if (url != null)

         return url;

      // Next, try to locate this resource through the system classloader

      url = ClassLoader.getSystemClassLoader().getResource(path);

      // Anywhere else we should look?

      return url;

   }

你还是把这个文件放在classes目录吧