applicationContext.xml
<?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:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<!-- 配置EmployeeService对象 -->
<bean id="employeeService" class="com.service.imp.EmployeeService">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="departmentService" class="com.service.imp.DepartmentService">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="url" value="jdbc:sqlserver://localhost:1433"></property>
<property name="username" value="sa"></property>
<property name="password" value="hyj84884824"></property>
<property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
<!-- 连接吃启动的初始值 -->
<property name="initialSize" value="3"/>
<!-- 连接池最大值 -->
<property name="maxActive" value="500"/>
<!-- 最大空闲值 -->
<property name="maxIdle" value="2"/>
<!-- 最小空闲值,当空闲的连接数少于阀值,连接池会再去申请一些连接,防止洪峰来时 -->
<property name="minIdle" value="1"/>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<!-- 接管了hibernate对象映射文件 -->
<property name="mappingResources">
<list>
<value>com/domain/Employee.hbm.xml</value>
<value>com/domain/Department.hbm.xml</value>
</list>
</property>
<!-- 方言等。 -->
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.SQLServerDialect
hibernate.hbm2ddl.auto=update
</value>
</property>
</bean>
<!-- 配置事务管理器,统一管理sessionFactory的事务 -->
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<!-- 启用事务注解 -->
<tx:annotation-driven transaction-manager="txManager"/>
<!-- 配置action -->
<bean name="/login" class="com.yourcompany.struts.action.LoginAction" scope="prototype">
<property name="employeeServiceInter" ref="employeeService"/>
</bean>
<bean name="/addEmp" class="com.yourcompany.struts.action.EmployeeAction" scope="prototype">
<property name="departmentServicceInter" ref="departmentService"/>
<property name="employeeServiceInter" ref="employeeService"/>
</bean>
<bean name="/logout" class="com.yourcompany.struts.action.LoginAction" scope="prototype"/>
<bean name="/employee" class="com.yourcompany.struts.action.EmployeeAction"/>
<bean name="/goListEmpUi" class="com.yourcompany.struts.action.EmployeeAction">
<property name="employeeServiceInter" ref="employeeService"/>
</bean>
<bean name="/ChangeEmpUi" class="com.yourcompany.struts.action.EmployeeAction">
<property name="employeeServiceInter" ref="employeeService"/>
<property name="departmentServicceInter" ref="departmentService"/>
</bean>
<bean name="/GoChangeEmpUi" class="com.yourcompany.struts.action.EmployeeAction">
<property name="employeeServiceInter" ref="employeeService"/>
</bean>
<bean name="/delEmp" class="com.yourcompany.struts.action.EmployeeAction">
<property name="employeeServiceInter" ref="employeeService"/>
</bean>
</beans>