Hibernate的applicationContext.xml配置和web.xml配置

1、<!-jdbc.properties配置(SqlServer实例)->
jdbc.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
jdbc.url=jdbc:sqlserver://192.168.0.225:1433;databasename=vane
jdbc.username=sa
jdbc.password=000000

hibernate.dynamic-update=true
hibernate.generate_statistics=true
hibernate.show_sql=true
hibernate.dialect=org.hibernate.dialect.SQLServerDialect

<!-applicationContext.xml配置->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

<!--  资源定义 -->
<context:property-placeholder location="classpath:jdbc.properties" />

<!--  数据源定义 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close" p:driverClassName="${jdbc.driverClassName}"
p:url="${jdbc.url}" p:username="${jdbc.username}" p:password="${jdbc.password}" />
<!-- 持久层 Hibernate 会话工厂 -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
p:dataSource-ref="dataSource">
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.dynamic-update">${hibernate.dynamic-update}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.generate_statistics">${hibernate.generate_statistics}</prop>
</props>
</property>
<property name="mappingResources">
<list>
   <!-- 实体对象配置 -->
<value>com/Student.hbm.xml</value>
</list>
</property>
</beans>


<!-sessionFactory注入到Hibernate的类中->
<!-- 或者这样注入到Dao中 -->

<bean id="petDao" class="com.jenter.pet.dao.PetDaoHibImpl">
  <property name="sessionFactory" ref="sessionFactory"/>
</bean>



2、<!-web.xml加入applicationContext.xml->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/applicationContext.xml</param-value>
</context-param>
<!-这句话就将applicationContext.xml加进来了->

你可能感兴趣的:(sql,xml,Hibernate,Web,jdbc)