(SSM框架 配置文件)
★SSM框架整合(配置文件源码)
<!-- 前言-->
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
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-3.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">
<!-- 1.开启注解 -->
<context:component-scan base-package="com.zb"/>
<!-- 2.视图解析器 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name ="suffix" value="/jsp"/>
</bean>
<!-- 3.引入数据源配置文件 -->
<context: property-placeholder location="classpath:database.properties"/>
<!-- 4.连接数据源 -->
<bean id ="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${driver}"/>
<property name ="url" value="${url}"/>
<property name ="username" value ="${user}"/>
<property name ="password" value ="${password}"
</bean>
<!-- 5.配置SqlSessionFactoryBean -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean" >
<!-- 获取数据源 -->
<property name="dataSource" ref="dataSource"/>
<!-- Mybatis别名-->
<property name="typeAliasePackage" value="com.gr.ssm.po"/>
<!-- Mybatis 配置文件-->
<property name="configLocation" value="classpath:mybatis-config.xml"/>
<!--配置SQL映射文件信息 -->
<property name ="mapperLocaltions">
<list>
<value>classpath:com/gr/ssm/dao/*.xml</value>
</list>
<property>
<!-- 6.注入注射器(接口扫描器)-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!-- 当有多个sessionFactory实例时显示注入SqlsessionFactory <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/> -->
<property name="basePackage" value="com.gr.ssm.dao"/>
</bean>
<!-- 7.事务管理器 -->
<bean id="txManager" value="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- 8. 声明式事务 -->
<tx:advice id="txAdivce" transaction-manager="txManager">
<tx:attributes>
<tx:method="find*" propagation="REQUIRED"/>
<tx:method="save*" propagation="REQUIRED"/>
<tx:method="del*" propagation="REQUIRED"/>
<tx:method="update*" propagation="REQUIRED"/>
<tx:method="*" propagation="REQUIRED"/>
</tx:attributes>
<tx:advice>
<!-- 9. 定义切面 -->
<aop:config>
<!-- 定义切点 -->
<aop:pointcut expression="execution(* com.gr.ssm.service..*.*(..) " id="pc")"/>
<!-- 将事务增强和切点结合 -->
<aop :advisor advice-ref="txAdvice" pointcut-ref="pc"/>
</aop:config>
<!-- 10.静态资源映射 -->
<import resource="spring-mvc.xml"/>