整合Service层

所有的service实现类都要放到spring容器中管理。由spring创建数据库连接池,并由spring来管理事务

1)配置applicationContext-service.xml

在src/main/resources/spring目录下新建一个applicationContext-service.xml文件:

<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/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-4.2.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx.xsd"><!--指定注解扫描包路径--><context:component-scan base-package="com.oak.xiyuyou.service"/>
</beans>

2)创建service包

在src/main/java下新建service包

2)配置事务

下面我们来配置事务,我们把事务单独提出来进行配置,在src/main/resources新添加applicationContext-tras.xml配置:

<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/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-4.2.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx.xsd"><!-- 事务管理器,用的是Spring JDBC的事务管理器 --><bean id="transactionManager"class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><!-- 数据源 --><property name="dataSource" ref="dataSource" /></bean><!-- 通知 --><tx:advice id="txAdvice" transaction-manager="transactionManager"><tx:attributes><!-- 传播行为 --><tx:method name="save*" propagation="REQUIRED" /><tx:method name="insert*" propagation="REQUIRED" /><tx:method name="delete*" propagation="REQUIRED" /><tx:method name="update*" propagation="REQUIRED" /><tx:method name="find*" propagation="SUPPORTS" read-only="true" /><tx:method name="get*" propagation="SUPPORTS" read-only="true" /></tx:attributes></tx:advice><!-- 切面 --><aop:config><aop:advisor advice-ref="txAdvice"pointcut="execution(* com.oan.xiyuyou.service.*.*(..))" /></aop:config>
</beans>

3)配置web.xml初始化spring容器

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"><display-name>netctoss0702_ssm_demo05</display-name><welcome-file-list><welcome-file>index.html</welcome-file><welcome-file>index.htm</welcome-file><welcome-file>index.jsp</welcome-file><welcome-file>default.html</welcome-file><welcome-file>default.htm</welcome-file><welcome-file>default.jsp</welcome-file></welcome-file-list><!-- 初始化Spring容器 --><context-param><param-name>contextConfigLocation</param-name><param-value>classpath:spring/applicationContext-*.xml</param-value></context-param><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener></web-app>

Service整合完毕。

旅游后台管理系列——SSM框架Service层整合相关推荐

  1. SSM框架的优势整合

    SSM框架的优势整合 SSM为开发解决了什么问题? SSM框架:Spring+SpringMVC+Mybatis Spring框架的优势: 提供IOC容器,解决了层与层之间的耦合问题(对象之间的依赖关 ...

  2. SSM 框架 Maven项目整合实例

    2019独角兽企业重金招聘Python工程师标准>>> SSM 框架 Maven项目整合实例1: 转载学习:https://blog.csdn.net/Peng_Hong_fu/ar ...

  3. (转)淘淘商城系列——SSM框架整合之Service层整合

    http://blog.csdn.net/yerenyuan_pku/article/details/72721108 上文我们一起学习了Dao层的整合,本文将教大家如何整合Service层.  我们 ...

  4. (转)淘淘商城系列——SSM框架整合之Dao层整合

    http://blog.csdn.net/yerenyuan_pku/article/details/72721093 一个项目中往往有三层即Dao层.Service层和Web层,看标题就知道了,本文 ...

  5. 【SSM】第一课 超市订单管理平台--SSM框架整合

    概念 在Java服务端开发中,Spring+SpringMVC+Mybatis搭建MVC三层架构完成项目的创建流程是开发者学习框架编程的必经之路,这里我们使用一个项目来完成整个的开发过程,后期会用一系 ...

  6. 后台管理UI的框架选择

    一.EasyUI easyui是一种基于jQuery的用户界面插件集合. easyui为创建现代化,互动,JavaScript应用程序,提供必要的功能. 使用easyui你不需要写很多代码,你只需要通 ...

  7. 关于ssm框架的全部整合(一) 2021.05.09

    ······今天整合了关于ssm框架的mybatis还有spring还有springmvc,关于spring因为开了弹幕,一直满屏用注解用注解自己分心了,所以第一遍的理解不太透侧,但是还好啃透了. · ...

  8. SSM框架超级详细整合记录:Spring+Spring MVC+MyBatis+Maven+MySQL

    1.前言 本文主要对SSM框架整合的过程进行记录,作为之后参考的依据. 1.1.参考文章 Spring代码实例系列-绪论 Spring MVC代码实例系列-绪论 MyBatis代码实例系列-绪论 1. ...

  9. ssm框架搭建和整合流程

    Spring + SpringMVC + Mybatis整合流程 1      需求 1.1     客户列表查询 1.2     根据客户姓名模糊查询 2      整合思路 第一步:整合dao层 ...

  10. idea ssm框架 mysql_IDEA 2017 整合SSM框架(使用Maven创建工程)

    SSM框架(Spring+SpringMVC+MyBatis)是目前Java WEB开发使用较多的框架,搭建起来起来比较麻烦,之前也曾搭建成功过.这次通过结合SSM开发的相关学习视频,再一次系统性的将 ...

最新文章

  1. P3743 kotori的设备(二分答案,思维,线性)难度⭐⭐⭐
  2. 警惕!油性混合皮肤护理的误区 - 健康程序员,至尚生活!
  3. 指数基金日涨跌幅python_看懂巴菲特推荐的指数基金定投,Python验证
  4. 细数二十世纪最伟大的十大算法
  5. audacity_如何在Audacity中快速编辑多个文件
  6. IO流入门-第十二章-ObjectInputStream_ObjectOutputStream
  7. 全栈入门_启动数据栈入门包(2020)
  8. 关闭所有的screen
  9. cache数据库教程
  10. 计算机组成原理微课版(谭志虎主编)预习笔记
  11. 【网络学习】Coverity代码检查工具详细介绍
  12. 怎样使用裁剪图片软件随意裁剪图片尺寸?
  13. 记SUSE系统安装DM8开发版(单实例)
  14. 对应分析图解读的七种方法
  15. 如何把一条条的微信语音合成一个mp3文件?
  16. springboot之微信支付与退款
  17. 从零开始的Android:Android应用程序开发概述
  18. [PAT乙级]1025 反转链表 (思路+精简代码)
  19. CSS高级属性之 box-shadow 详解
  20. 炒币机器人:囤币,我们是“一囤到底”还是“半路抛弃

热门文章

  1. Hadoop 集群 傻瓜式搭建手记 (一) 软件准备
  2. 【ccpc网络赛】YJJ's Salesman【1010】【树状数组+离散化+dp】
  3. POJ - 2533(动态规划 —— 最长子序列)
  4. 入坑AI一路过来走过的弯路和思考
  5. Java修改带回显吗_修改的是根据自定义标签进行处理回显
  6. classpath java配置_Java环境变量中classpath是必须配置吗?
  7. linux 大型c程序,c – 如何以编程方式在大型Linux应用程序中“拉网线”?
  8. [Docker] Docker安装和简单指令
  9. Swagger入参为List
  10. Zabbix 微信报警Python版(带监控项波动图片)