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> <!-- 配置事务切面 --> 

转载于:https://www.cnblogs.com/yr0215/p/8025567.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值