SSM框架搭建详细解析
总结了一下搭建SSM框架流程,在以后用到的时候方便回头使用。
使用工具:MyEclipse 2015;Tomcat 8版本;jdk1.8版本。
首先:
1:创建一个WebProject项目,jdk1.8 Tomcat8 最后勾选web.xml配置文件。
然后:
2.将相应的Jar包导入lib文件下。总共35个Jar包,将OJBDBC也导入进去。
3.配置web.xml文件。
配置2个内容。一个是Spring,一个是Spring MVC的配置。
Spring配置信息
1:通过全局上下文参数来加载Spring配置文件
2:配置监听器。
在web.xml中继续配置Spring MVC;
Spring MVC的配置信息。
- 1:首先配置servlet。通过Servlet标签配置dispatchServlet。需要一个初始化参数 ,加载spring MVC配置文件。
- 2:配置mapping。
然后还需要配置一下中文乱码解决问题。继续在web.xml中配置相关信息。
然后,进行下一步。
4:加入3个配置文件。Spring,Spring MVC,Mybatis 这三个配置文件需要加入。
将配置文件放在src根目录下即可。
Spring的扫描包:配置了事物。(applicationContext.xml);
- 1:自动扫描:根据注解创建实例化,控制反转。(4种方式)
- 2:引入配置文件。jdbc的驱动包等信息。
- 3:配置数据源。需要的信息根据第二步中的jdbc中的配置文件来引用。
- 4:配置MyBatis的SqlSessionFactory:有了它才可以使用MyBatis(1:数据源:第三步配置的数据源。2:自动扫描mappers.xml文件。所有的映射文件。放在一个对应的路径下。3:加载MyBatis的配置文件。)
- 5:DAO层接口包。该包下的所有都会被实例化。
- 6:配置事物管理:交由Spring来管理。(1:定义事物传播属性。)
- 7:配置事物切面。
- 8:异常处理相关。
- 关于Spring的配置信息以代码形式展现给大家:
<?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:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- 自动扫描 -->
<context:component-scan base-package="com.sys.dao" />
<context:component-scan base-package="com.sys.service" />
<context:component-scan base-package="com.sys.entity"/>
<!-- 引入配置文件,可以使用${}语法,location:指定读取文件的路径 -->
<context:property-placeholder location="classpath:jdbc.properties"/>
<!-- 配置数据源 -->
<bean id="dataSource"
class="com.mchange.v2.c3p0.ComboPooledDataSource"
p:driverClass="${jdbc.driverClassName}"
p:jdbcUrl="${jdbc.url}"
p:user="${jdbc.username}"
p:password="${jdbc.password}"
p:initialPoolSize="${jdbc.initialSize}"
p:maxPoolSize="${jdbc.maxActive}"/>
<!-- 配置mybatis的sqlSessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!-- 自动扫描mappers.xml文件 -->
<property name="mapperLocations" value="classpath:mybatis/mappers/*.xml"></property>
<!-- mybatis配置文件 -->
<property name="configLocation" value="classpath:mybatis/mybatis-config.xml"></property>
</bean>
<!-- DAO接口所在包名,Spring会自动查找其下的类 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.sys.dao" />
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
</bean>
<!-- (事务管理)transaction manager, use JtaTransactionManager for global tx -->
<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="add*" propagation="REQUIRED" />
<tx:method name="append*" propagation="REQUIRED" />
<tx:method name="insert*" propagation="REQUIRED" />
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="modify*" propagation="REQUIRED" />
<tx:method name="edit*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="remove*" propagation="REQUIRED" />
<tx:method name="repair" propagation="REQUIRED" />
<tx:method name="delAndRepair" propagation="REQUIRED" />
<tx:method name="get*" propagation="SUPPORTS" />
<tx:method name="find*" propagation="SUPPORTS" />
<tx:method name="load*" propagation="SUPPORTS" />
<tx:method name="search*" propagation="SUPPORTS" />
<tx:method name="datagrid*" propagation="SUPPORTS" />
<tx:method name="*" propagation="SUPPORTS" />
</tx:attributes>
</tx:advice>
<!-- 配置事务切面 -->
<aop:config>
<aop:pointcut id="serviceOperation"
expression="execution(* com.sys.service.*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="serviceOperation" />
</aop:config>
<!-- 异常统一处理 -->
<!-- <bean id="exceptionResolver" class="com.sys.util.HandlerException"/> -->
</beans>
Spring MVC:(servlet-mvc.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:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- 使用注解的包,包括子集 -->
<context:component-scan base-package="com.sys.controller" />
<!-- 添加数据转换的注解驱动 -->
<mvc:annotation-driven>
<mvc:message-converters>
<bean class="org.springframework.http.converter.StringHttpMessageConverter"/>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/>
</mvc:message-converters>
</mvc:annotation-driven>
<!-- 视图解析器 -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/" />
<property name="suffix" value=".jsp"></property>
</bean>
<!-- 上传组件 -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!-- 设置上传的编码格式 -->
<property name="defaultEncoding" value="utf-8"/>
<!-- 设置最大上传大小 -->
<property name="maxUploadSize" value="5242880"/>
</bean>
<!-- 静态资源配置设置:除了控制器一概不管理 -->
<mvc:default-servlet-handler/>
</beans>
MyBatis 配置文件(mybatis-config.xml)放置在src目录下的mabatis文件夹内。
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<!-- 别名 -->
<typeAliases>
<package name="com.sys.entity"/>
</typeAliases>
</configuration>
JDBC文件与Log4j配置文件。(日志文件,将错误信息保存在日志文件,前台不能显示错误文件,也可保存用户访问信息,以及数据库操作的信息)。
log4j.properties配置源码:
log4j.rootLogger=info,appender1,appender2
log4j.appender.appender1=org.apache.log4j.ConsoleAppender
log4j.appender.appender2=org.apache.log4j.FileAppender
log4j.appender.appender2.File=D:/logs/news/logFile.txt
log4j.appender.appender1.layout=org.apache.log4j.TTCCLayout
log4j.appender.appender2.layout=org.apache.log4j.TTCCLayout
在jdbc配置文件中修改相关信息。(需要自己修改;#代表注释)。
jdbc.properties配置源码
jdbc.driverClassName=oracle.jdbc.driver.OracleDriver //Oracle数据库
jdbc.url=jdbc\:oracle\:thin\:@localhost\:1521\:jredu //数据库名
jdbc.username=OnlineTest //数据库表
jdbc.password=Jredu12345 //数据库密码
jdbc.initialSize=0
jdbc.maxActive=20
jdbc.maxIdle=20
jdbc.minIdle=1
jdbc.maxWait=60000
至此,关于SSM框架搭建已经成功,在下一个博客之中,会实现一个SSM搭建框架,实现一个简单的登录功能。
如有疑问或需要或指教的朋友:
希望朋友多多指导,小白萌新渴望学习。
QQ:1090239782
SSM框架搭建详细解析的更多相关文章
- SSM 框架搭建
SSM框架搭建(Spring.SpringMVC.Mybatis) 一:基本概念 Spring : Spring是一个开源框架,Spring是于2003 年兴起的一个轻量级的Java 开发框 ...
- SSM框架搭建教程(从零开始,图文结合)
1.准备 IntelliJ IDEA Tomcat JDK Maven mysql spring.springmvc.mybatis 了解 现在假设如上条件你都具备,那么通过我这篇博客 你一定可以整合 ...
- SSM框架搭建web服务器实现登录功能(Spring+SpringMVC+Mybatis)
初学java EE,虽然知道使用框架会使开发更加便捷高效,但是对于初学者来说,感到使用框架比较迷惑,尤其是各种jar包的引用.各种框架的配置.注解的使用等等. 最好的学习方法就是实践,于是下载了一个现 ...
- 实习小结(二)--- SSM框架搭建
SSM项目框架搭建 前几天做了一个学生信息管理的项目,使用纯控制台输入,查询数据库,将信息在控制台中打印,功能完善得差不多之后,老师让将这个项目移植到Web中,使用Spring+SpringMVC+M ...
- SpringMVC笔记——SSM框架搭建简单实例
落叶枫桥 博客园 首页 新随笔 联系 订阅 管理 SpringMVC笔记——SSM框架搭建简单实例 简介 Spring+SpringMVC+MyBatis框架(SSM)是比较热门的中小型企业级项目开发 ...
- idea ssm框架搭建
1.分享一篇完整的ssm框架搭建连接 大牛博客:https://www.cnblogs.com/toutou/p/ssm_spring.html#_nav_0 2.我的搭建的完整项目连接,可以进入我的 ...
- ssm框架搭建整合测试
下载各种jar包 mybatis下载 https://github.com/mybatis/mybatis-3/releases mysql驱动下载 http://mvnrepository.com/ ...
- SSM(Spring+SpringMVC+Mybatis)框架搭建详细教程【附源代码Demo】
[前言] 应某网络友人邀约,需要一个SSM框架的Demo作为基础学习资料,于是乎,就有了本文.一个从零开始的SSM框架Demo对一个新手来说,是非常重要的,可大大减少在学习过程中遇到的各种各样的坑,说 ...
- [转]SSM(Spring+SpringMVC+Mybatis)框架搭建详细教程【附源代码Demo】
一.新建项目 运行IDEA,进入初始化界面,然后我们选择新建项目(进入主界面新建项目也是一样的) 在Maven选项卡里面找到对应的java web选项,然后我们点下一步 这一步填入组织等信息,这里比较 ...
随机推荐
- 简单谈谈网络抓包,特别是thrift 接口
按照惯例先谈谈最近情况,最近不是刚好跨年吗?看到很多人都在写年度总结,所以我也在写年度总结文章(其实之前我基本没有写过的,今年有点感触,也想记录一下),结果发现写起来有点多,之前还想着元旦前发出来,结 ...
- Hadoop之WordCount
求平均数是MapReduce比较常见的算法,求平均数的算法也比较简单,一种思路是Map端读取数据,在数据输入到Reduce之前先经过shuffle,将map函数输出的key值相同的所有的value值形 ...
- 架构设计哲学【三种方式:支持DevOps的原则】
三种方式:支持DevOps的原则 2012年8月22日作者Gene Kim 45条评论 这篇文章是杨波老师分享的一篇文章:这几年对他架构影响最深的一篇文章.主要描述是关于DevOps的,但对系统架构同 ...
- tail常用命令总结
tail命令作用: tail命令用途是依照要求将指定的文件的最后部分输出到标准设备,通常是终端,通俗讲来,就是把某个档案文件的最后几行显示到终端上,假设该档案有更新,tail会自己主动刷新,确保你看到 ...
- linux下安装docker容器
1.安装环境 此处在Centos7进行安装,可以使用以下命令查看CentOS版本 lsb_release -a 在 CentOS 7安装docker要求系统为64位.系统内核版本为 3.10 以上,可 ...
- 消息队列 ---常用的 MQ 中间件
目前市面上比较常用的 MQ(Message Queue,消息队列)中间件有 RabbitMQ.Kafka.RocketMQ,如果是轻量级的消息队列可以使用 Redis 提供的消息队列,其中 Redis ...
- Java 实现简单的 Socket 通信
Java socket 封装了传输层的实现细节,开发人员可以基于 socket 实现应用层.本文介绍了 Java socket 简单用法. 1. 传输层协议 传输层包含了两种协议,分别是 TCP (T ...
- redis存json数据时选择string还是hash
redis存json数据时选择string还是hash 我们在缓存json数据到redis时经常会面临是选择string类型还是选择hash类型去存储.接下来我从占用空间和IO两方面来分析这两种类型的 ...
- 【设计模式】Java设计模式精讲之原型模式
简单记录 - 慕课网 Java设计模式精讲 Debug方式+内存分析 & 设计模式之禅-秦小波 文章目录 1.原型模式的定义 原型-定义 原型-类型 2.原型模式的实现 原型模式的通用类图 原 ...
- 【Linux】在docker上部署grafana+zabbix监控实录
------------------------------------------------------------------------------------------------- ...