Spring配置SessionFactory
2012-11-12 21:54
141 查看
1.不用dataSource引入hibernate.cfg.xml
hibernate.cfg.xml放在src目录下。(hibernate的配置文件)
2.丢掉hibernate.cfg.xml
1>使用注解:
2>不使用注解:
3>使用packagesToScan
它Spring 2.5.6的新特性。
hibernate.cfg.xml放在src目录下。(hibernate的配置文件)
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="configLocation"> <value>classpath:hibernate.cfg.xml</value> </property> </bean>
2.丢掉hibernate.cfg.xml
1>使用注解:
<bean id="sessionFactory" class="...hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="annotatedClasses"> <list> <value>com.bjsxt.model.User</value> <value>com.bjsxt.model.Log</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect"> org.hibernate.dialect.MySQLDialect </prop> <prop key="hibernate.show_sql">true</prop> </props> </property> </bean>
2>不使用注解:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="mappingResources"> <!-- mappingResouces属性用来列出全部映射文件 --> <list><!-- 以下用来列出Hibernate映射文件 --> <value>jsf/web/entity/User.hbm.xml</value> </list> </property> <!-- 定义Hibernate的SessionFactory的属性 --> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.format_sql">true</prop> </props> </property> </bean>
3>使用packagesToScan
它Spring 2.5.6的新特性。
<bean id="sessionFactory" class="...hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="packagesToScan"> <list> <value>com.bjsxt.model</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> <prop key="hibernate.show_sql">true</prop> </props> </property> </bean>
相关文章推荐
- Spring 中sessionFactory的几种配置方式
- 在Spring3+Hibernate4环境中配置Quartz定时器,注入sessionFactory
- hibernate3-maven-plugin 使用 spring applicationContext.xml中的sessionFactory配置(1)
- Spring配置SessionFactory
- spring配置hibernate的sessionFactory的几种方法
- Spring配置文件中SessionFactory引用Hibernate配置产生问题的思考
- Spring配置SessionFactory
- Spring配置sessionFactory的三种方法
- Spring3与Hibernate4整合,Spring中配置Hibernate基于XML和annotation的sessionFactory方式。
- Spring 中sessionFactory的几种配置方式
- 关于Spring中配置LocalSessionFactoryBean来生成SessionFactory
- hibernate3-maven-plugin 使用 spring applicationContext.xml中的sessionFactory配置(2)
- Spring配置SessionFactory
- Spring 中sessionFactory的几种配置方式
- spring管理SessionFactory中XML配置
- java-spring文件配置sessionFactory及相关数据源示例代码
- Spring 中sessionFactory的几种配置方式
- Spring 中sessionFactory的几种配置方式
- spring 配置sessionFactory
- 毕业设计(五)---spring学习笔记(3)之-dataSource,sessionFactory,hibernateTemplate,事务 的简单配置。