Spring配置文件中FactoryBean配置4种方式(2种hibernate,1种ibatis,1种mybatis)

本文详细介绍了如何在Spring框架中整合多种ORM(Object-Relational Mapping)工具,包括ibatis、Hibernate以及MyBatis的配置方法。针对每种ORM工具,提供了具体的XML配置示例,并解释了如何设置数据源、SessionFactory等关键组件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.ibaits(加载proxool.xml配置文件 见hmzw)

<!--ibatis SqlMapClient-->
	<bean id="sqlMapClient"
		class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
		<property name="configLocation">
			<value>
				classpath:com/s2sh/persistence/sqlmap/SqlMapConfig.xml
			</value>
		</property>
		<property name="dataSource" ref="dataSource" />
		<property name="lobHandler" ref="lobHandler" />
	</bean>

2.hibernate(LocalSessionFactoryBean) (1.spring管理hibernate (proxool方式连接) 见wop   2.标准hibernate HibernateDaoSupport (spring-orm) 见ssh)

<bean id="sessionFactory"
		class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
		<property name="dataSource">
			<ref bean="DataSource" />
		</property>
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">
					org.hibernate.dialect.Oracle9Dialect
				</prop>
				<!--  <prop key="hibernate.show_sql">true</prop> -->
			</props>
		</property>
	</bean>


3.hibernate(AnnotationSessionFactoryBean)(spring管理hibernate(dbcp方式连接)  见hm_dzjc)

(附:springjdbcTemplate可直接加载数据源dataSource 见hm_dzjc)

<!-- Hibernate配置 -->
	<bean id="sessionFactory"
		class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<property name="namingStrategy">
			<bean class="org.hibernate.cfg.ImprovedNamingStrategy" />
		</property>
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">${hibernate.dialect}</prop>
				<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
				<prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
				<prop key="hibernate.connection.release_mode">after_transaction</prop>
			</props>
		</property>
		<property name="packagesToScan" >
			<list>
				<value>com.s2sh.cac.entity</value>
				<value>com.s2sh.entity</value>
			</list>

		</property>
	</bean>

4.mybatis

<!-- ================================ MyBatis SqlSession配置 ========================================= -->
	<!-- 使用SqlSessionFactoryBean工厂产生SqlSession对象,方便后期注入Dao -->
	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<property name="configLocation" value="classpath:mybatis_config/Configuration.xml"></property>
		<!-- <property name="transactionFactoryClass" value="org.mybatis.spring.transaction.SpringManagedTransactionFactory" />
		<property name="transactionFactoryClass" value="org.apache.ibatis.transaction.managed.ManagedTransactionFactory" /> -->
	</bean>



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值