()-servlet.xml中剥离出的hibernate.cfg.xml

  1 <?xml version="1.0" encoding="UTF-8"?>
  2 
  3 <beans xmlns="http://www.springframework.org/schema/beans"
  4  
  5 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
  6  
  7 xmlns:tx="http://www.springframework.org/schema/tx"
  8  
  9 xsi:schemaLocation="
 10 
 11 http://www.springframework.org/schema/beans
 12 
 13 http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
 14 
 15 http://www.springframework.org/schema/context
 16 
 17 http://www.springframework.org/schema/context/spring-context-3.0.xsd
 18 
 19 http://www.springframework.org/schema/tx
 20 
 21  http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
 22 
 23 <context:property-placeholder location="classpath:jdbc.properties" />
 24  
 25 <context:component-scan base-package="net.roseindia" />
 26  
 27 <tx:annotation-driven transaction-manager="hibernateTransactionManager"
 28  
 29 />
 30  
 31 <bean id="jspViewResolver"
 32  
 33 class="org.springframework.web.servlet.view.InternalResourceViewResolver">
 34  
 35 <property name="viewClass"
 36  
 37 value="org.springframework.web.servlet.view.JstlView"/>
 38  
 39 <property name="prefix" value="/WEB-INF/view/"/>
 40  
 41 <property name="suffix" value=".jsp"/>
 42  
 43 </bean>
 44  
 45 <bean id="dataSource"
 46  
 47 class="org.springframework.jdbc.datasource.DriverManagerDataSource">
 48  
 49 <property name="driverClassName" value="${database.driver}" />
 50  
 51 <property name="url" value="${database.url}" />
 52  
 53 <property name="username" value="${database.user}" />
 54  
 55 <property name="password" value="${database.password}" />
 56  
 57 </bean>
 58 
 59 <bean id="sessionFactory"
 60         class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
 61         <property name="dataSource" ref="dataSource" />
 62         <property name="configLocation">
 63             <value>classpath:hibernate.cfg.xml</value>
 64         </property>
 65         <property name="configurationClass">
 66             <value>org.hibernate.cfg.AnnotationConfiguration</value>
 67         </property>
 68         <property name="hibernateProperties">
 69             <props>
 70        <prop key="hibernate.dialect">${hibernate.dialect}</prop>
 71        <prop key="hibernate.show_sql">${hibernate.show_sql}</prop> 
 72             </props>
 73         </property>
 74     </bean>
 75  <!-- <bean id="sessionFactory"
 76  
 77 class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
 78  
 79 <property name="dataSource" ref="dataSource" />
 80  
 81 <property name="annotatedClasses">
 82  
 83 <list>
 84  
 85 <value>net.roseindia.model.Article</value>
 86  
 87 </list>
 88  
 89 </property>
 90  
 91 <property name="hibernateProperties">
 92  
 93 <props>
 94  
 95 <prop key="hibernate.dialect">${hibernate.dialect}</prop>
 96  
 97 <prop key="hibernate.show_sql">${hibernate.show_sql}</prop> 
 98 
 99 </props>
100  
101 </property>
102  
103 </bean>
104  
105 
106  -->
107 <bean id="hibernateTransactionManager"
108  
109 class="org.springframework.orm.hibernate3.HibernateTransactionManager">
110  
111 <property name="sessionFactory" ref="sessionFactory" />
112  
113 </bean>
114 
115 </beans>

hibernate.cfg.xml

 1 <?xml version='1.0' encoding='utf-8'?>
 2 <!DOCTYPE hibernate-configuration PUBLIC
 3     "-//Hibernate/Hibernate Configuration DTD//EN"
 4     "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
 5  
 6 <hibernate-configuration>
 7     <session-factory>
 8         <mapping class="net.roseindia.model.Article" />
 9     </session-factory> 
10 </hibernate-configuration>

结构

 

posted @ 2013-11-19 15:49  Kstyjobx!!  阅读(207)  评论(0编辑  收藏  举报