SSM整合第二步之Spring
目录
Spring整合Mybatis
Spring整合Service层
Spring整合Mybatis
新建spring-dao.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"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttps://www.springframework.org/schema/context/spring-context.xsd"><!-- 配置整合mybatis --><!-- 1.关联数据库文件 --><context:property-placeholder location="classpath:database.properties"/><!-- 2.数据库连接池 --><!--数据库连接池dbcp 半自动化操作 不能自动连接c3p0 自动化操作(自动的加载配置文件 并且设置到对象里面)--><bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"><!-- 配置连接池属性 --><property name="driverClass" value="${jdbc.driver}"/><property name="jdbcUrl" value="${jdbc.url}"/><property name="user" value="${jdbc.username}"/><property name="password" value="${jdbc.password}"/><!-- c3p0连接池的私有属性 --><property name="maxPoolSize" value="30"/><property name="minPoolSize" value="10"/><!-- 关闭连接后不自动commit --><property name="autoCommitOnClose" value="false"/><!-- 获取连接超时时间 --><property name="checkoutTimeout" value="10000"/><!-- 当获取连接失败重试次数 --><property name="acquireRetryAttempts" value="2"/></bean><!-- 3.配置SqlSessionFactory对象 --><bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"><!-- 注入数据库连接池 --><property name="dataSource" ref="dataSource"/><!-- 配置MyBaties全局配置文件:mybatis-config.xml --><property name="configLocation" value="classpath:mybatis-config.xml"/></bean><!-- 4.配置扫描Dao接口包,动态实现Dao接口注入到spring容器中 --><!--解释 :https://www.cnblogs.com/jpfss/p/7799806.html--><bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"><!-- 注入sqlSessionFactory --><property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/><!-- 给出需要扫描Dao接口包 --><property name="basePackage" value="com.lt.dao"/></bean></beans>
Spring整合Service层
新建spring-service.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"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.xsd"><!-- 扫描service相关的bean --><context:component-scan base-package="com.lt.service" /><!--BookServiceImpl注入到IOC容器中--><bean id="BookServiceImpl" class="com.lt.service.BookServiceImpl"><property name="bookMapper" ref="bookMapper"/></bean><!-- 配置事务管理器 --><bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><!-- 注入数据库连接池 --><property name="dataSource" ref="dataSource" /></bean></beans>
SSM整合第二步之Spring相关推荐
- SSM整合(springMVC+spring+Mybatis)
目录 前言 (一)三个框架的应用 SpringMVC Spring Mybatis (二)整合步骤 包结构 1.pom..xml导入依赖 2.配置web.xml文件 3.创建springmvc.xml ...
- SSM学习——SSM整合案例(Spring+SpringMVC+Mybatis)(13)
这里写目录标题 要求 Spirng整合Mybatis Spirng整合SpringMVC 表与实体类的创建 创建层级 Dao层 Service层 controller层 接口测试 业务层`servic ...
- SSM 整合 4:Spring IoC 容器基于的两个重要接口 BeanFactory 和 ApplicationContext
文章目录 前言 一.BeanFactory 接口 1.1.加载 Spring 配置文件创建 BeanFactory 接口实例 1.2.开发中的运用以及使用说明 二.ApplicationContext ...
- SSM整合框架搭建(适合新手)
SSM整合(SpringMvc+Spring+Mybatis) 首先创建一个Dynamic Web Project(JavaWeb动态工程) 创建一个xxx.xxx.xxx.controller包用来 ...
- [转]SSM框架——详细整合教程(Spring+SpringMVC+MyBatis)
使用SSM(spring.SpringMVC和Mybatis)已经有三个多月了,项目在技术上已经没有什么难点了,基于现有的技术就可以实现想要的功能,当然肯定有很多可以改进的地方.之前没有记录SSM整合 ...
- SSM整合(2): spring 与 mybatis 整合
在进行完spring与springmvc整合之后, 继续 spring与mybatis的整合. 既然是操作数据库, 那必然不能缺少了连接属性 一. db.properties jdbc.driver= ...
- java框架ssm整合_SSM三大框架整合详细教程(Spring+SpringMVC+MyBatis)
使用 SSM ( Spring . SpringMVC 和 Mybatis )已经有三个多月了,项目在技术上已经没有什么难点了,基于现有的技术就可以实现想要的功能,当然肯定有很多可以改进的地方.之前没 ...
- Spring ---- ssm整合
文章目录 SSM(spring+springMVC+Mybatis)整合流程简介 项目基础结构搭建 spring 整合mybatis 创建MyBatis映射文件 创建Spring配置文件.整合Myba ...
- ssm如何支持热部署_最新Spring Boot实战文档推荐:项目搭建+配置+SSM整合
在Spring Boot项目中,正常来说是不存在XML配置,这是因为Spring Boot不推荐使用XML,注意,排不支持,Spring Boot推荐开发者使用Java配置来搭建框架, Spring ...
最新文章
- 图解5G NR帧结构
- Azure SQL Database (19) Stretch Database 概览
- amh支持java吗_AMH 6.0 发布,国内领先的云主机面板
- audio标签控制音量_HTML5中audio与video标签的使用
- java-Set集合源码学习
- 分支管理---创建与合并分支
- Marketing Cloud里取得系统contact数目的API
- gpu填充速率 计算_【经典回顾】Nvidia GPU 上的 CNN 计算速度变迁
- java 封装 继承 堕胎_Java的继承、封装和多态
- python开发中遇到的难题_初学者在Python开发中常见的问题(上)
- Oracle RAC环境下如何定位并杀掉最终阻塞的会话
- 第12课:HA下的Spark集群工作机制解密
- 拓端tecdat|R语言拟合扩展的Rasch模型分析试题质量
- 类的加载过程详解之过程二:Linking(链接)阶段
- 算法:求1+2+3+...+n
- 利用Python白玩steam游戏,我是专业的
- 美文听力:别错过机会
- 小米6无线显示无法连接服务器,小米手机:无法连接WiFi怎么解决?
- Xilinx SDK 中 的 'No rule to make target ' / '没有规则可以创建...'
- Linux下的Curses库的下载与安装