日期:2014-05-18  浏览次数:20672 次

讨论:Eclipse+Spring+Hibernate配置中的路径问题(分不够开新贴给分)
小第刚开始搞Spring,在Eclipse环境下开发。

/WEB-INF/web.xml配置

<display-name> ims </display-name>
<context-param>
    <param-name> contextConfigLocation </param-name>
    <param-value> /WEB-INF/applicationContext.xml </param-value>
</context-param>
<context-param>
    <param-name> log4jConfigLocation </param-name>
    <param-value> /WEB-INF/log4j.properties </param-value>
</context-param>
 
<listener>
    <listener-class> org.springframework.web.util.Log4jConfigListener </listener-class>
</listener>
<listener>
    <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class>
</listener>

在/WEB-INF/applicationContext.xml配置如下
<bean   id= "propertyConfigurer "   class= "org.springframework.beans.factory.config.PropertyPlaceholderConfigurer ">
<property   name= "location "   value= "/WEB-INF/jdbc.properties "   />
</bean>

<bean   id= "dataSource "
class= "org.springframework.jdbc.datasource.DriverManagerDataSource ">
<property   name= "driverClassName "   value= "${jdbc.driverClassName} "   />
<property   name= "url "   value= "${jdbc.url} "   />
<property   name= "username "   value= "${jdbc.username} "   />
<property   name= "password "   value= "${jdbc.password} "   />
</bean>

<!--   JNDI   DataSource   for   J2EE   environments   -->
<!--
<bean   id= "dataSource "   class= "org.springframework.jndi.JndiObjectFactoryBean ">
<property   name= "jndiName "   value= "java:comp/env/jdbc/petclinic "/>
</bean>
-->

<!--   Hibernate   SessionFactory   -->
<bean   id= "sessionFactory "
class= "org.springframework.orm.hibernate3.LocalSessionFactoryBean ">
<property   name= "dataSource "   ref= "dataSource "   />
<property   name= "mappingResources ">
<value> hibernate-mapping.hbm.xml </value>
</property>
<property   name= "hibernateProperties ">
<props>
<prop   key= "hibernate.dialect "> ${hibernate.dialect} </prop>
<prop   key= "hibernate.show_sql "> true </prop>
<prop   key= "hibernate.generate_statistics "> true </prop>
<prop   key= "hibernate.hbm2ddl.auto "> update </prop>
</props>
</property>
<property   name= "eventListeners ">
<map>
<entry   key= "merge ">
<bean   class= "org.springframework.orm.hibernate3.support.IdTransferringMergeEventListener "   />
</entry>
</map>
</property>
</bean>

以上代码在不同的应用服