Demo entry 6761943

陈海宏

   

Submitted by anonymous on Oct 09, 2018 at 06:47
Language: XML. Code size: 2.4 kB.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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.xsd
	http://www.springframework.org/schema/context
	http://www.springframework.org/schema/context/spring-context.xsd
	http://www.springframework.org/schema/aop
	http://www.springframework.org/schema/aop/spring-aop.xsd
	http://www.springframework.org/schema/tx 
	http://www.springframework.org/schema/tx/spring-tx.xsd">


	<!-- 配置c3p0连接池 -->
	<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
		<!-- 注入属性 -->
		<property name="driverClass" value="${jdbc.driverClass}"></property>
		<property name="jdbcUrl" value="${jdbc.url}"></property>
		<property name="user" value="${jdbc.username}"></property>
		<property name="password" value="${jdbc.password}"></property>
	</bean>



	<!-- 管理bean -->
	<bean id="customerService" class="com.ssh.service.impl.CustomerServiceImpl">
		<property name="customerDao" ref="customerDao"></property>
	</bean>

	<bean id="customerDao" class="com.ssh.dao.impl.CustomerDaoImpl">
		<!-- 向dao中注入sessionFactory -->
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>



	<!-- 将struts的Action交给spring管理 -->
	<bean id="customerAction" class="com.ssh.web.action.CustomerAction"
		scope="prototype"><!-- 设置 action为多例的 -->
		<!-- 手动注入service -->
		<property name="customerService" ref="customerService"></property>
	</bean>



	<!-- spring整合hibernate -->
	<!-- 引入hibernate的配置信息 -->
	<bean id="sessionFactory"
		class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
		<!-- 引入hibernate的配置文件 -->
		<property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
	</bean>




	<!-- 配置事务管理器 -->
	<bean id="transactionManager"
		class="org.springframework.orm.hibernate5.HibernateTransactionManager">
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>
	<!-- 开启事务 -->
	<tx:annotation-driven transaction-manager="transactionManager" />


</beans>

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).