前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >spring整合中application.xml配置

spring整合中application.xml配置

作者头像
沁溪源
发布2020-09-03 11:00:10
6660
发布2020-09-03 11:00:10
举报
文章被收录于专栏:沁溪源
代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
		xmlns="http://www.springframework.org/schema/beans" 
		xmlns:context="http://www.springframework.org/schema/context" 
		xmlns:aop="http://www.springframework.org/schema/aop" 
		xmlns:tx="http://www.springframework.org/schema/tx" 
		xsi:schemaLocation="http://www.springframework.org/schema/beans 
		http://www.springframework.org/schema/beans/spring-beans-4.2.xsd 
		http://www.springframework.org/schema/context 
		http://www.springframework.org/schema/context/spring-context-4.2.xsd 
		http://www.springframework.org/schema/aop 
		http://www.springframework.org/schema/aop/spring-aop-4.2.xsd 
		http://www.springframework.org/schema/tx 
		http://www.springframework.org/schema/tx/spring-tx-4.2.xsd "> 
		
		<!-- 扫描配置数据源文件 -->
		<context:property-placeholder location="classpath:jdbc.properties"/>
		<!-- 配置数据源 -->
		<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
			<property name="driverClass" value="${jdbc.driverClass}"/>
			<property name="jdbcUrl" value="${jdbc.jdbcUrl}"/>
			<property name="user" value="${jdbc.user}"/>
			<property name="password" value="${jdbc.password}"/>
		</bean>
		
		<!-- 配置LocalSessionFactoryBean spring 提供整合hibernate工厂bean -->
		<bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
			<!-- 注解数据源,进入源码中可以知道sessionFactory有该属性 -->
			<property name="dataSource" ref="dataSource"/>
			<!-- 注入hiberna的核心配置文件属性 -->
			<property name="hibernateProperties">
				<props>
					<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialec</prop>
					<prop key="hibernate.hbm2ddl.auto">update</prop>
					<prop key="hibernate.show_sql">true</prop>
					<prop key="hibernate.format_sql">true</prop>
				</props>
			</property>
			<!-- 注入hibernate的映射文件属性 -->
			<property name="mappingLocations">
				<list>
					<value >classpath:com/itwx/bos/domain/*.xml</value>
				</list>
			</property>
		</bean>
		
		<!-- 配置事务管理器 -->
		<bean id="transactionManger" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
			<!-- 注入sessionFactory -->
			<property name="sessionFactory" ref="sessionFactory"></property>
		</bean>
		
		<!-- 扫描组件 -->
		<context:component-scan base-package="com.itwx.bos"/>
		
		<!-- 开启事务 -->
		<tx:annotation-driven/>
		
		<!-- 支持spring注解 -->
		<context:annotation-config/>
</beans>
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2018/04/06 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档