简单配置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: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">


<!-- 基于 mapper 接口通过动态代理产生实现类 -->
<!-- <bean id="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
通过 value 值,扫描该包下的接口,从而产生实现类
<property name="basePackage" value="com.ssm.dao"></property>
该 bean 下会产生 dao 接口的实现类,并且该 bean 中会有 sqlSessionFactory 的依赖,配置之
<property name="sqlSessionFactory" ref="sqlSessionFactory"></property>
</bean> -->


<!-- 3、sqlSessionFactory bean -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- sqlsessionfactory 依赖注入 datasource -->
<property name="dataSource" ref="dataSource"></property>

<!--
管理 mybatis 的映射配置文件,该属性可管理多个配置文件
name:表示该标签是管理 mybatis 的映射配置文件
value:表示在类路径下需要管理的 mybatis 的映射配置文件
-->
<property name="mapperLocations" value="classpath:com/ssm/bean/*.xml"></property>

<!--
在包的前提下为数据 bean 取别名
name:表示是基于包为数据 bean 取别名
value:表示为哪个包下取别名
-->
<property name="typeAliasesPackage" value="com.ssm.bean"></property>
</bean>

<!-- 引入数据源配置文件 -->
<context:property-placeholder location="classpath:jdbc.properties"/>
<!-- 5、dataSource bean -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<!-- 配置 c3p0 连接池参数 -->
<property name="driverClass" value="${db.driver}"></property>
<property name="jdbcUrl" value="${db.url}"></property>
<property name="user" value="${db.username}"></property>
<property name="password" value="${db.password}"></property>
</bean>

<!-- 6、声明式事务 bean -->
<bean id="dataSourceTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>

<!--
6、aop 切面 bean 配置
expression:根据指定的表达式选择要切入的位置
id:切面标签的 id
<aop:aspect>:用于配置事务的前置操作和后置操作,但是在该情景下不适用
<aop:advisor>:通知需要执行的事务
advice-ref:引入事务通知
pointcut-ref:引入切入点
-->
<!-- <aop:config>
<aop:pointcut expression="execution(* com.yidu.foodfresh.dao.impl.*.*(..))" id="mypointcut"/>
<aop:advisor advice-ref="txadvice" pointcut-ref="mypointcut"/>
</aop:config> -->

<!-- 基于注解声明式事务完成事务的切面 -->
<!-- <tx:annotation-driven transaction-manager="dataSourceTransactionManager"/> -->

<!-- 基于上下文扫描组件 -->
<context:component-scan base-package="com.ssm.*"></context:component-scan>

</beans>

转载于:https://www.cnblogs.com/4AMLJW/p/ssm_ljw_201909091527.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值