spring与mybasic整合配置



  <!-- 启动@AspectJ框架的支持 -->
  <aop:aspectj-autoproxy></aop:aspectj-autoproxy>
 
  <context:component-scan base-package="com.lovo">
  <context:excluede-filter type="" expression=""></context:excluede-filter>
  </context:component-scan>
 
  <!-- 配置数据源DataSource -->
  <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerData">
  <!-- &amp;在配置文件中代表& -->
  <property name="url" value="jdbc:mysql:///test0323?characterEncoding=utf-8"></property>
  <property name="username" value="root"></property>
  <property name="password" password="12345"></property>
  </bean>
 
  <!-- 配置Session工厂 -->
  <bean id="sessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
  <property name="dataSource" ref="dataSource"></property>
  <!-- 加载mybatis.cfg.xml文件 -->
  <property name="configLocation" value="classpath:mybatis.cfg.xml"></property>
  </bean>
 
  <!-- 将Mapper配置文件和Session进行关联 -->
  <bean id="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
  <property name="basePackage" value="com.lovo.mapper"></property>
  <property name="sqlSessionFactory" ref="sqlSessionFactoryBean"></property>
  </bean>
<!-- 配置事务管理 --> 
<bean id="dataSourceTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>

<!-- 事务管理方式一,适合于单数据库,使用注解的方式来管理事务
<tx:annotation-driven transaction-manager="dataSourceTransactionManager"/>-->

<!-- 事务管理方式二,采用springAOP来声明式地处理事务,声明式就是脱离java代码,通常是声明在配置中 -->
<!-- 声明一个通知 -->
<tx:advice id="txAdvice" transaction-manager="dataSourceTransactionManager">
<tx:attributes>
<!-- name方法名,propagation事务类型  -->
<tx:method name="*" propagation="SUPPORTS" read-only="true"></tx:method>
<!-- rollback-for出现异常时回滚 -->
<tx:method name="save*" propagation="REQUIRED" read-only="false" rollback-for="java.lang.Exception"></tx:method>
</tx:attributes>
</tx:advice> 

<!-- 配置AOP事务关联 -->
<aop:config>
<!-- 定义一个切点 -->
<aop:pointcut expression="execution(* com.lovo.service.*ServiceImpl.*(..)" id="serviceMethod"/>
<!-- 将通知和切点关联起来 -->
<aop:advisor advice-ref="txAdvice" pointcut-ref="serviceMethod"/>
</aop:config>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值