创建Maven就不用多说了,下面直接看Pom.xml里面的依赖吧

    <properties>
        <!-- spring版本号 -->
        <spring.version>5.0.0.RELEASE</spring.version>
        <!-- 因为使用了Spring5,如果jackson版本过低会报错 -->
        <jackson.version>2.9.3</jackson.version>
    </properties>
    <dependencies>
        <!-- spring核心包 -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-oxm</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <!-- AOP begin -->
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>1.7.4</version>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>1.7.4</version>
        </dependency>
        <dependency>
            <groupId>cglib</groupId>
            <artifactId>cglib</artifactId>
            <version>3.1</version>
        </dependency>
        <!-- AOP end -->

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <!-- 添加MyBatis依赖 -->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.4.5</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.0.8</version>
        </dependency>
        <!-- 阿里巴巴的数据库连接池 -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.0.16</version>
        </dependency>
        <!-- spring结成mybatis -->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>1.3.1</version>
        </dependency>
        <!-- jsp标准标签库 -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
        <!-- 日志 -->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.16</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.6.1</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-nop</artifactId>
            <version>1.6.4</version>
        </dependency>
        <!-- Junit测试工具 -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.7</version>
            <scope>test</scope>
        </dependency>
        <!-- jackson -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>${jackson.version}</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>${jackson.version}</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>${jackson.version}</version>
        </dependency>
        <!-- servlet -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <!-- provided表明该包只在编译和测试的时候用 -->
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.1</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    <!-- 配置以下信息,可以避免mapper.xml加载不成功 -->
    <build>
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
        </resources>
        <!-- tomcat启动插件 -->
        <plugins>
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <uriEncoding>UTF-8</uriEncoding>
                    <path>/</path>
                    <port>8</port>
                </configuration>
            </plugin>
        </plugins>
    </build>

配置文件

web.xml

 <!-- 配置启动记载spring配置文件 -->
     <context-param>
         <param-name>contextConfigLocation</param-name>
         <param-value>classpath:applicationContext.xml</param-value>
     </context-param>
     <!-- 配置监听器加载spring -->
     <listener>
         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
     </listener>

     <!-- UTF-8编码的Filter -->
     <filter>
         <filter-name>encodingFilter</filter-name>
         <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
         <init-param>
             <param-name>encoding</param-name>
             </param-value>
         </init-param>
         <init-param>
             <param-name>forceEncoding</param-name>
             <param-value>true</param-value>
         </init-param>
     </filter>
     <filter-mapping>
         <filter-name>encodingFilter</filter-name>
         <url-pattern>/*</url-pattern>
     </filter-mapping>
     <!-- 配置SpringMVC -->
     <servlet>
         <servlet-name>ssm</servlet-name>
         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
         <init-param>
             <param-name>contextConfigLocation</param-name>
             <param-value>classpath:Springmvc.xml</param-value>
         </init-param>
         <!-- 配置springmvc什么时候启动,参数必须为整数 -->
         <!-- 如果为0或者大于0,则springMVC随着容器启动而启动 -->
         <!-- 如果小于0,则在第一次请求进来的时候启动 -->
         <load-on-startup>1</load-on-startup>
     </servlet>
     <servlet-mapping>
         <servlet-name>ssm</servlet-name>
         <!-- 所有的请求都进入springMVC -->
         <url-pattern>/</url-pattern>
     </servlet-mapping>

applicationContext.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"
     xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee"
     xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
     xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:util="http://www.springframework.org/schema/util"
     xsi:schemaLocation="
         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/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.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
         http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
         http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
         http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
     <!-- 扫描注解 -->
     <context:component-scan base-package="com.yk" />

     <!-- 配置 读取properties文件 jdbc.properties -->
     <context:property-placeholder location="classpath:jdbc.properties" />
     <!-- 配置 数据源 -->
     <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
         <property name="driverClassName" value="${jdbc.driver}" />
         <property name="url" value="${jdbc.url}" />
         <property name="username" value="${jdbc.username}" />
         <property name="password" value="${jdbc.password}" />
         <property name="validationQuery" value="SELECT 1" />
         <!-- 初始化大小 -->
         <property name="initialSize" value="0" />
         <!-- 连接池最小空闲 -->
         <property name="minIdle" value="0" />
         <!-- 连接池最大使用连接数量 -->
         <property name="maxActive" value="20" />
         <!-- 获取连接最大等待时间 -->
         <property name="maxWait" value="60000" />
         <!-- 获取连接时测试是否有效 -->
         <property name="testOnBorrow" value="false" />
         <!-- 归还连接时是否测试有效 -->
         <property name="testOnReturn" value="false" />
         <!-- 连接空闲时测试是否有效 -->
         <property name="testWhileIdle" value="true" />
         <!-- 逐出连接的检测时间间隔(主要用于检测空闲的连接) -->
         <property name="timeBetweenEvictionRunsMillis" value="60000" />
         <!-- 配置一个连接在池中最小生存的时间,单位是毫秒,最小逐出时间 -->
         <property name="minEvictableIdleTimeMillis" value="25200000" />
         <!-- 打开关闭“赃”连接(调用过getVendorConnection方法)功能 -->
         <property name="removeAbandoned" value="true" />
         <!-- 连接泄漏的超时时间 -->
         <property name="removeAbandonedTimeout" value="1800" />
         <!-- 关闭泄漏的连接时打印堆栈信息 -->
         <property name="logAbandoned" value="true" />
         <!-- 监控数据库 -->
         <!-- <property name="filters" value="stat" /> -->
         <property name="filters" value="mergeStat" />
     </bean>
     <!-- sessionFactory 将spring和mybatis整合 Spring与Mybatis相关的配置文件 typeAliasesPackage:可以配置多个,用','号分隔
         basePackage:可以配置多个,用','号分隔 -->
     <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
         <property name="dataSource" ref="dataSource" />
         <!-- 加载mapper配置文件 -->
         <property name="mapperLocations" value="classpath*:mapper/*.xml" />
         <!-- 别名 -->
         <property name="typeAliasesPackage" value="com.yk.entity" />
         <!-- 加载Mybatis配置文件 -->
         <property name="configLocation" value="classpath:/mybatis-config.xml" />
     </bean>
     <!-- 配置扫描器 -->
     <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
         <property name="basePackage" value="com.yk.dao" />
         <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
     </bean>

     <!-- 配置事物 -->
     <!-- 事务管理器 -->
     <bean id="transactionManager"
         class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
         <!-- 数据源 -->
         <property name="dataSource" ref="dataSource" />
     </bean>
     <!-- 切面 -->
     <aop:config>
         <aop:advisor advice-ref="txAdvice"
             pointcut="execution(* com.yk.service.*.*(..))" />
     </aop:config>
     <!-- 通知 -->
     <tx:advice id="txAdvice" transaction-manager="transactionManager">
         <tx:attributes>
             <!-- 传播行为 -->
             <tx:method name="save*" propagation="REQUIRED" />
             <tx:method name="insert*" propagation="REQUIRED" />
             <tx:method name="add*" propagation="REQUIRED" />
             <tx:method name="create*" 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="select*" propagation="SUPPORTS" read-only="true" />
             <tx:method name="get*" propagation="SUPPORTS" read-only="true" />
             <tx:method name="query*" propagation="SUPPORTS" read-only="true" />
             <tx:method name="*" propagation="SUPPORTS" read-only="true" />
         </tx:attributes>
     </tx:advice>

 </beans>

jdbc.properties

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url
jdbc.username=root
jdbc.password=root

log4j.properties

  ### 设置###
 log4j.rootLogger = DEBUG,stdout,D,E

 ### 输出信息到控制抬 ###
 log4j.appender.stdout = org.apache.log4j.ConsoleAppender
 log4j.appender.stdout.Target = System.out
 log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
 log4j.appender.stdout.layout.ConversionPattern = [%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} method:%l%n%m%n

 ### 输出DEBUG 级别以上的日志到=E://logs/error.log ###
 log4j.appender.D = org.apache.log4j.DailyRollingFileAppender
 log4j.appender.D.File = E://logs/log.log
 log4j.appender.D.MaxFileSize = 10MB
 log4j.appender.D.Threshold = ALL
 log4j.appender.D.Append = true
 log4j.appender.D.Threshold = DEBUG
 log4j.appender.D.layout = org.apache.log4j.PatternLayout
 log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss}  [ %t:%r ] - [ %p ]  %m%n

 ### 输出ERROR 级别以上的日志到=E://logs/error.log ###
 log4j.appender.E = org.apache.log4j.DailyRollingFileAppender
 log4j.appender.E.File =E://logs/error.log
 log4j.appender.D.MaxFileSize = 10MB
 log4j.appender.D.Threshold = ALL
 log4j.appender.E.Append = true
 log4j.appender.E.Threshold = ERROR
 log4j.appender.E.layout = org.apache.log4j.PatternLayout
 log4j.appender.E.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss}  [ %t:%r ] - [ %p ]  %m%n

 ###显示SQL语句部分
 log4j.logger.com.mybatis=DEBUG
 log4j.logger.com.mybatis.common.jdbc.SimpleDataSource=DEBUG
 log4j.logger.com.mybatis.common.jdbc.ScriptRunner=DEBUG
 log4j.logger.com.mybatis.sqlmap.engine.impl.SqlMapClientDelegate=DEBUG
 log4j.logger.java.sql.Connection=DEBUG
 log4j.logger.java.sql.Statement=DEBUG
 log4j.logger.java.sql.PreparedStatement=DEBUG

Springmvc.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:context="http://www.springframework.org/schema/context"
     xmlns:mvc="http://www.springframework.org/schema/mvc"
     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
         http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
     <!-- 配置Controller扫描 -->
     <context:component-scan base-package="com.yk.controller" />

     <!-- 配置注解驱动 -->
     <mvc:annotation-driven />

     <!-- 配置视图解析器 -->
     <bean
         class="org.springframework.web.servlet.view.InternalResourceViewResolver">
         <!-- 前缀 -->
         <property name="prefix" value="/WEB-INF/" />
         <!-- 后缀 -->
         <property name="suffix" value=".jsp" />
     </bean>

     <!-- 静态资源映射 -->
     <!-- <mvc:resources mapping="/static/**" location="/static/" cache-period="31556926"
         /> -->

 </beans>

mybatis-config.xml

 <?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>
     <settings>
     <!-- 打印sql -->
         <setting name="logImpl" value="STDOUT_LOGGING" />
     </settings>
 </configuration>

项目右键→Run As → maven build..

自此一个简单的SSM框架搭建完成,第一次写博客,也主要是为了记录自己在学习中遇到的问题,可以学习到的东西,方便自己以后回顾

通过Maven简单搭建SSM框架的更多相关文章

  1. 在Eclipse中利用maven整合搭建ssm框架

    首先说明用到的框架: spring  +  springMVC  +  mybatis 构建工具:maven 开发工具:eclipse 开发环境:win10      java版本:jdk1.8    ...

  2. Eclipse中使用Maven搭建SSM框架

    Eclipse中不使用Maven搭建SSM框架:https://www.cnblogs.com/xuyiqing/p/9569459.html IDEA中使用Maven搭建SSM框架:https:// ...

  3. 详解intellij idea搭建SSM框架(spring+maven+mybatis+mysql+junit)(下)

    在上一篇(详解intellij idea 搭建SSM框架(spring+maven+mybatis+mysql+junit)(上))博文中已经介绍了关于SSM框架的各种基础配置,(对于SSM配置不熟悉 ...

  4. 详解intellij idea搭建SSM框架(spring+maven+mybatis+mysql+junit)(上)

    SSM(Spring+SpringMVC+MyBatis)框架集由Spring.SpringMVC.MyBatis三个开源框架整合而成,常作为数据源较简单的web项目的框架. 其中spring是一个轻 ...

  5. 使用maven搭建ssm框架的javaweb项目

    目前主流的javaweb项目,常会用到ssm(Spring+Spring MVC+Mybatis)框架来搭建项目的主体框架,本篇介绍搭建SSM框架的maven项目的实施流程.记之共享! 一.SSM框架 ...

  6. 使用maven搭建SSM框架

    使用maven搭建SSM框架,首先得准备好maven环境. 搭建maven环境 第一步:下载maven http://maven.apache.org/download.cgi 下载后解压就可以了. ...

  7. 使用maven搭建ssm框架环境

    1.前言 因为经常换环境,在搭ssm框架的时候老是出错,所以记录一下最近搭建的环境,以供参考. 本文讲解如何使用maven搭建ssm框架,并能用于简单的登录注册. IDE:IDEA,JDK版本:1.8 ...

  8. Idea + maven搭建SSM框架

    1.打开idea,新建项目,选择maven骨架,然后填写包名和项目名称,一直下一步. 接着下一步,配置项目的maven环境 创建完成之后,如下图:(上边的项目名字只是例子,具体的以自己搭建的项目名为准 ...

  9. Maven项目搭建(二):Maven搭建SSM框架

    上一章给大家讲解了如何使用Maven搭建web项目. 这次给大家介绍一下怎么使用Maven搭建SSM框架项目. 首先我们来看一下pom.xml的属性介绍: project: pom的xml根元素. p ...

随机推荐

  1. OCFS2 Fencing

    OCFS2 FencingPosted on February 8, 2011 by Abdulhameed Basha I am very excited to start writing my e ...

  2. 10-stack

    c++ stl栈stack介绍 C++ Stack(堆栈) 是一个容器类的改编,为程序员提供了堆栈的全部功能,——也就是说实现了一个先进后出(FILO)的数据结构. c++ stl栈stack的头文件 ...

  3. SqlServer——字符串处理函数

    1) ASCII Format:ASCII ( character_expression ) Function:返回表达式最左端字符的ASCII值. eg: select ASCII('abcdef' ...

  4. 文件操作putc

    putc是把一个字符写入到指定文件中,每写一个字符,文件指针自动加1. 我写了一个随机生成255字符到d:/456.txt的程序. int main() { FILE *p; int num[255] ...

  5. CF 662C Binary Table

    用FWT优化计算. 首先发现行数很小,想到一个暴力的方法,就是以一个二进制位$0$表示这一行不翻转而二进制位$1$表示这一行翻转,然后$2^n$枚举出所有行的翻转情况,再$O(m)$计算所有的结果. ...

  6. LIS和LCS LCIS

    首先介绍一下LIS和LCS的DP解法O(N^2) LCS:两个有序序列a和b,求他们公共子序列的最大长度 我们定义一个数组DP[i][j],表示的是a的前i项和b的前j项的最大公共子序列的长度,那么由 ...

  7. 认识Web前端、Web后端、桌面app和移动app新开发模式 - 基于Node.js环境和VS Code工具

    认识Web.桌面和移动app新开发模式 - 基于Node.js环境和VS Code工具 一.开发环境的搭建(基于win10) 1.安装node.js和npm 到node.js官网下载安装包(包含npm ...

  8. 在VS2010中使用Git【图文】(转)

    出处:http://www.cnblogs.com/oec2003/archive/2012/11/13/2768860.html 在之前的一片博客<Windows 下使用Git管理Github ...

  9. jenkins持续集成之Global Tool Configuration的配置

    Global Tool Configuration的配置过程: 1.点击系统管理2.点击 Global Tool Configuration3.必须配置: jdk git ant maven 1.点击 ...

  10. SQL server 累加求和

    1. SELECT SalesOrderID, ProductID, OrderQty    ,SUM(OrderQty) OVER(PARTITION BY SalesOrderID) AS Tot ...