把一个applicationContext.xml拆分(还可以再分出action部分和tx事务部分)
1、dao部分
<!-- 配置DAO --> <bean id="employeeDao" class="cn.bdqn.jboa.dao.hibimpl.EmployeeDaoHibImpl"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <bean id="claimVoucherDao" class="cn.bdqn.jboa.dao.hibimpl.ClaimVoucherDaoHibImpl"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <bean id="claimVoucherDetailDao" class="cn.bdqn.jboa.dao.hibimpl.ClaimVoucherDetailDaoHibImpl"> <property name="sessionFactory" ref="sessionFactory" /> </bean>
2、service部分
<!-- 配置业务层 --> <bean id="employeeService" class="cn.bdqn.jboa.service.impl.EmployeeServiceImpl"> <property name="employeeDao" ref="employeeDao"></property> </bean> <bean id="claimVoucherService" class="cn.bdqn.jboa.service.impl.ClaimVoucherServiceImpl"> <property name="claimVoucherDao" ref="claimVoucherDao" /> <property name="claimVoucherDetailDao" ref="claimVoucherDetailDao" /> </bean>
3、基本类
<!-- 通过<import resource="xxx.xml">方式注入多个配置文件 --> <!-- <import resource="applicationContext-dao.xml" /> <import resource="applicationContext-service.xml" /> --> <!-- 定义dbcp数据源 --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <!-- 指定JDBC驱动类 --> <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"> </property> <!-- 提供连接数据库的URL地址 --> <property name="url" value="jdbc:oracle:thin:@localhost:1521:orcl"> </property> <!-- 提供连接数据库的用户名和密码 --> <property name="username" value="bdqn"></property> <property name="password" value="bdqn"></property> </bean> <!-- 定义SessionFactory Bean --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <!-- 为LocalSessionFactoryBean注入定义好的数据源 --> <property name="dataSource"> <ref bean="dataSource" /> </property> <!-- 添加Hibernate配置参数 --> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect"> org.hibernate.dialect.OracleDialect </prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.format_sql">true</prop> </props> </property> <!-- 添加对象关系映射文件 --> <!-- <property name="mappingResources"> <list> <value>cn/bdqn/jboa/entity/ClaimVoucher.hbm.xml</value> <value>cn/bdqn/jboa/entity/ClaimVoucherDetail.hbm.xml</value> <value>cn/bdqn/jboa/entity/Employee.hbm.xml</value> <value>cn/bdqn/jboa/entity/CheckResult.hbm.xml</value> <value>cn/bdqn/jboa/entity/Position.hbm.xml</value> <value>cn/bdqn/jboa/entity/Department.hbm.xml</value> <value>cn/bdqn/jboa/entity/Dictionary.hbm.xml</value> </list> </property> --> <property name="mappingDirectoryLocations"> <list> <value>classpath:cn/bdqn/jboa/entity/</value> </list> </property> </bean> <!-- 定义事务管理器 --> <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <tx:advice id="txAdvice" transaction-manager="txManager"> <tx:attributes> <tx:method name="find*" read-only="true" /> <tx:method name="search*" read-only="true" /> <tx:method name="query*" read-only="true" /> <tx:method name="add*" propagation="REQUIRED" /> <tx:method name="del*" propagation="REQUIRED" /> <tx:method name="update*" propagation="REQUIRED" /> <tx:method name="do*" propagation="REQUIRED" /> <tx:method name="*" propagation="REQUIRED" read-only="true" /> </tx:attributes> </tx:advice> <aop:config> <!-- 定义切入点 --> <aop:pointcut id="serviceMethod" expression="execution(* cn.bdqn.jboa.service.*.*(..))" /> <!-- 将事务通知与切入点组合 --> <aop:advisor advice-ref="txAdvice" pointcut-ref="serviceMethod" /> </aop:config> <!-- 控制层 (id为struts.xml中的class) 以下每个bean必须都要增加scope="prototype"属性 --> <!-- <bean id="userAction" class="cn.bdqn.jboa.action.UserAction" scope="prototype"> <property name="employeeService" ref="employeeService"></property> </bean> -->
时间: 2024-12-28 01:18:06