1. 程式人生 > >ssm框架整合,pom.xml依賴分析

ssm框架整合,pom.xml依賴分析

宣告,使用spring5.0.7.RELEASE /mybatis3.4.6/mysql8/JDK8進行整合;

採用父工程子模組方式
整合分2大部分:
spring和springmvc、spring和mybatis整合

spring和springmvc、

1、分別搭建spring以及springmvc,spring和springmvc是無縫結合的,這也是spring火熱的重要原因之一;
2、下面分析下spring整合springmvc都需要哪些依賴,這裡簡寫只寫artifactId
①spring整合junit 、列印日誌
junit/spring-test/slf4j-log4j12
②spring中xml和註解配合使用
spring-context
③spring 核心ioC和AOP,使用到事務就要用到jdbcTemplate以及事務相關的依賴
spring-jdbc/druid/spring-aspects/spring-tx
要連線資料庫吧
mysql-connector-java
springmvc需要哪些依賴呢?web專案、、jsp、jstl、servlet處理json的jackson等
spring-webmvc、spring-web/servlet-api/jsp-api、jstl、jackson-databind

spring和mybatis整合、

mybatis作為持久層框架、處理dao層,除了引入mybatis相關的依賴,整合需要引入mybatis-spring相結合的依賴;
1、spring整合mybatis
mybatis、mybatis-spring/連線資料庫、DataSource、log4j都已存在、/
Jackson-databind 、jsp、servlet等均已存在

其他配置:

tomcat7 外掛
mapper.xml若放在mapper目錄下,不放在resources目錄下,maven工程加在不到的;
需配置指定載入xml的配置在pom檔案中;

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>baidu-parent</
artifactId
>
<groupId>com.baidu.parent</groupId> <version>0.0.1-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <groupId>com.baidu</groupId> <artifactId>ssm</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <name>ssm Maven Webapp</name> <!-- FIXME change it to the project's website --> <url>http://www.example.com</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>1.7</maven.compiler.source> <maven.compiler.target>1.7</maven.compiler.target> </properties> <!--spring和springmvc、spring和mybatis整合 --> <dependencies> <!-- 單元測試、日誌jar/log4j.properties檔案 --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> </dependency> <!--spring、需要註解/整合jdbcTemplate/整合單元測試spring-test/Junit&&log4j上面有/ 面向AOP、使用事務TX/ --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> </dependency> <!-- jdbcTemplate需要連線資料庫、事務處理又需要資料來源dataSource --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aspects</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> <version>5.0.7.RELEASE</version> </dependency> <!--springmvc spring-web、springmvc /需要servlet、jsp、jstl/ spring整合單元測試已存在/ 註解spring-context已存在/jdbc模板以及連線資料庫已存在/ springmvc需要處理json格式資料引入jackson-databind --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>5.0.7.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jsp-api</artifactId> </dependency> <dependency> <groupId>jstl</groupId> <artifactId>jstl</artifactId> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> </dependency> <!--上 --> <!-- spring整合mybatis mybatis、mybatis-spring/連線資料庫、DataSource、log4j都已存在、/ Jackson-databind 、jsp、servlet等均已存在 --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> </dependency> </dependencies> <build> <finalName>ssm</finalName> <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --> <plugins> <plugin> <artifactId>maven-clean-plugin</artifactId> <version>3.0.0</version> </plugin> <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging --> <plugin> <artifactId>maven-resources-plugin</artifactId> <version>3.0.2</version> </plugin> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.7.0</version> </plugin> <plugin> <artifactId>maven-surefire-plugin</artifactId> <version>2.20.1</version> </plugin> <plugin> <artifactId>maven-war-plugin</artifactId> <version>3.2.0</version> </plugin> <plugin> <artifactId>maven-install-plugin</artifactId> <version>2.5.2</version> </plugin> <plugin> <artifactId>maven-deploy-plugin</artifactId> <version>2.8.2</version> </plugin> <!-- 配置tomcat外掛 --> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <configuration> <port>8080</port> <path>/</path> <uriEncoding>utf-8</uriEncoding> </configuration> </plugin> </plugins> </pluginManagement> <!-- 配置可以載入maven 工程中 xml檔案 --> <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.xml</include> </includes> <filtering>true</filtering> </resource> <resource> <directory>src/main/resources</directory> <includes> <include>**/*.xml</include> <include>**/*.properties</include> </includes> </resource> </resources> </build> </project>