<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd"
default-autowire="byName">
<!-- 配置DataSource接口,这个我们可以直接用C3P0作为数据连接池
bean的命名规则:类名首字母小写,后面的不变
-->
<bean id="dataSource" destroy-method="close" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="oracle.jdbc.driver.OracleDriver"/>
<property name="jdbcUrl" value="jdbc:oracle:thin:@localhost:1521:orcl"/>
<property name="user" value="hotelsup"/>
<property name="password" value="123"/>
<property name="maxPoolSize" value="40"/>
<property name="minPoolSize" value="1"/>
<property name="initialPoolSize" value="1"/>
<property name="maxIdleTime" value="60"/>
<property name="checkoutTimeout" value="2000"/>
</bean>
<!-- 配置SqlSessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<!-- 指的是当前的mybatis的配置文件 -->
<property name="configLocation" value="classpath:mybatis-config.xml"></property>
</bean>

<!-- 首先告诉spring,所有的的对于数据库的操作都有事务开始管理 -->
<!-- 配置spring的声明式事务 -->
<!-- 事务管理的bean -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- 声明式事务的配置 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<!-- 事务的定义 -->
<tx:attributes>
<!-- propagation称之为事务的传播性 -->
<tx:method name="*" rollback-for="EXCEPTION" propagation="REQUIRED"/><!-- 所有的方法全部加入到事务中 -->
<tx:method name="get*" propagation="NEVER"/><!-- 不执行事务操作 -->
<tx:method name="set*" propagation="NEVER"/><!-- 不执行事务操作 -->
</tx:attributes>
</tx:advice>
<!-- AOP编程实现 -->
<aop:config>
<!-- 切入点的配置,哪些类或者哪些方法进入到切面中 -->
<aop:pointcut expression="execution(* com.jinglin.hotelsup.service..*(..))" id="allMethods"/>
<!-- 把切入点同事务整合在一起 -->
<aop:advisor advice-ref="txAdvice" pointcut-ref="allMethods"/>
</aop:config>
<!-- 使用annotation定义事务 -->
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" />


<!-- 通过spring的包的扫描的方式将这些包里的类扫描到spring的容器里 -->
<!-- 开启注解配置-->
<context:annotation-config/>
<!-- 对dao层的扫描,实际就是批量生成dao层的bean对象
生成的规则:bean的id名实际就是dao层类或接口的首字母小写
比如,UserInfoMapper->userInfoMapper
GoodsInfoMapper->goodsInfoMapper
-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!-- 配置扫描的包名 -->
<property name="basePackage" value="com.jinglin.hotelsup.dao.imp"></property>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
</bean>
<!-- 将service层全部扫描到spring容器里 -->
<context:component-scan base-package="com.jinglin.hotelsup.service"/>

</beans>

在Service层的体现

@Transactional // 注解,让事务失效,接触
@Service // 扫描了service 所以这里要注解
public class GoodsInfoService {
// 注入的dao层
@Autowired // 自动配置set get
private GoodsInfoMapper goodsInfoMapper;

// 查询
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public List<GoodsInfo> getlist() {
return goodsInfoMapper.getlist();
}

// 添加
public int adduser(GoodsInfo g) {
return goodsInfoMapper.additem(g);
}

}

配置一个完整的 applicacontext.xml的更多相关文章

  1. 一个完整配置例nginx.conf(生产环境中使用)

    一个完整的nginx配置案例,生产环境 一个完整配置例(生产环境中使用) user nobody nobody; worker_processes 4; worker_rlimit_nofile 51 ...

  2. 一个完整的JENKINS下的ANT BUILD.XML文件(Jenkins可以参考)

    一个完整的JENKINS下的ANT BUILD.XML文件 <?xml version="1.0" encoding="UTF-8"?> <p ...

  3. 转 一个web项目web.xml的配置中<context-param>配置作用

    一个web项目web.xml的配置中<context-param>配置作用   <context-param>的作用:web.xml的配置中<context-param& ...

  4. JBPM4.4+SSH 整合配置及完整实例

    整合jBPM4.4+ssh过程(spring接管struts2和hibernate,例中都整合在application.xml中,没有单独的jbpm.hibernate.cfg.xml): 1.在se ...

  5. 完整的struts.xml文件骨架

    完整的struts.xml文件骨架可以直接拿来用,修改一下就可以啦. <?xml version="1.0" encoding="UTF-8"?> ...

  6. 宙斯是一个完整的Hadoop的作业平台[转]

    https://github.com/alibaba/zeus 宙斯(zeus)是什么 宙斯是一个完整的Hadoop的作业平台从Hadoop任务的调试运行到生产任务的周期调度 宙斯支持任务的整个生命周 ...

  7. SpringBoot系列之三_一个完整的MVC案例

    这一节让我们来做一个完整的案例. 我们将使用MyBatis作为ORM框架,并以非常简单的方式来使用MyBatis,完成一个完整的MVC案例. 此案例承接上一节,请先搭建好上一节案例. 一.数据库准备 ...

  8. 手把手搭建一个完整的javaweb项目

    手把手搭建一个完整的javaweb项目 本案例使用Servlet+jsp制作,用MyEclipse和Mysql数据库进行搭建,详细介绍了搭建过程及知识点. 下载地址:http://download.c ...

  9. 一个完整的Core Data应用

    在这篇文章中,我们将建立一个小型但却全面支持Core Data的应用.应用允许你创建嵌套的列表:每个列表的item都可以有子列表,这将允许你创建非常深层次的item.为了让大家完整的了解发生了什么,我 ...

随机推荐

  1. Hibernate笔记一:HIbernate配置-HelloWorld

    hibernate介绍: Hibernate是一个开源的对象关系映射框架,它对JDBC进行了轻量级的对象封装,使Java程序员可以随心所欲的使用对象编程思维来操纵数据库. 它不仅提供了从java类到数 ...

  2. QA技术概览

    • 页面测试 页面测试,顾名思义,用来测试页面的表示和前端功能.这同时涉及单元测试和集成测试.我们会用Mocha 进行页面测试. • 跨页测试 跨页测试是对从一个页面转到另一个页面的功能的测试.比如电 ...

  3. Java 8 Learn Notes - Streams

    Main reference [1] http://winterbe.com/posts/2014/07/31/java8-stream-tutorial-examples 1. How Stream ...

  4. Bitwise And Queries

    Bitwise And Queries Time limit: 1500 msMemory limit: 128 MB You are given QQ queries of the form a\ ...

  5. aws上redhat安装lmysql服务记

    aws上redhat安装lmysql服务记 1.准备材料 1.1

  6. 第 12 章 MySQL 可扩展设计的基本原则

    前言: 随着信息量的飞速增加,硬件设备的发展已经慢慢的无法跟上应用系统对处理能力的要求了.此时,我们如何来解决系统对性能的要求?只有一个办法,那就是通过改造系统的架构体系,提升系统的扩展能力,通过组合 ...

  7. struts2.1.6教程三、在Action获取Scope对象

    引言:在前面的Action操作中,关键就是Action中的exectue方法,但是此方法并没有request.session.application等对象作为参数,自然就不能利用这些对象来操作.下面我 ...

  8. 基于底层的 XML 的解析方式详解

    在上一篇博客中,我们介绍了什么是 XML ,http://www.cnblogs.com/ysocean/p/6901008.html,那么这一篇博客我们介绍如何来解析 XML . 部分文档引用:ht ...

  9. Targeted Learning R Packages for Causal Inference and Machine Learning(转)

    Targeted learning methods build machine-learning-based estimators of parameters defined as features ...

  10. kafka 0.8.2 消息消费者 consumer

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...