1. 程式人生 > >一個完整的ssm專案環境配置

一個完整的ssm專案環境配置

http://blog.csdn.net/yubu_/article/details/75058962

本文使用maven來構建ssm專案,至於開始如何使用eclipse搭建web專案就不介紹了,主要介紹最麻煩的框架配置內容。

1.專案結構如下圖


2.pom.xml檔案

  1. <projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2.     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
    >
  3.     <modelVersion>4.0.0</modelVersion>
  4.     <groupId>Demo</groupId>
  5.     <artifactId>buoumall</artifactId>
  6.     <packaging>war</packaging>
  7.     <version>0.0.1-SNAPSHOT</version>
  8.     <name>buoumall Maven Webapp</name>
  9.     <url>http://maven.apache.org
    </url>
  10.     <properties>
  11.         <!-- spring版本號 -->
  12.         <spring.version>4.3.0.RELEASE</spring.version>
  13.         <!-- mybatis版本號 -->
  14.         <mybatis.version>3.2.6</mybatis.version>
  15.         <!-- log4j日誌檔案管理包版本 -->
  16.         <slf4j.version>1.7.7</slf4j.version
    >
  17.         <log4j.version>1.2.17</log4j.version>
  18.         <dubbo.version>2.8.4</dubbo.version>
  19.         <aspectj.version>1.7.3</aspectj.version>
  20.         <httpcomponents.version>4.4.1</httpcomponents.version>
  21.     </properties>
  22.     <dependencies>
  23.         <!-- 模板引擎 -->
  24.         <dependency>
  25.             <groupId>org.apache.velocity</groupId>
  26.             <artifactId>velocity</artifactId>
  27.             <version>1.7</version>
  28.         </dependency>
  29.         <!-- mybatis自動生成程式碼 start -->
  30.         <dependency>
  31.             <groupId>com.baomidou</groupId>
  32.             <artifactId>mybatis-plus</artifactId>
  33.             <version>2.0.2</version>
  34.         </dependency>
  35.         <dependency>
  36.             <groupId>org.mybatis.generator</groupId>
  37.             <artifactId>mybatis-generator-core</artifactId>
  38.             <version>1.3.2</version>
  39.         </dependency>
  40.         <!-- mybatis自動生成程式碼 end -->
  41.         <!-- junit測試 -->
  42.         <dependency>
  43.             <groupId>junit</groupId>
  44.             <artifactId>junit</artifactId>
  45.             <version>4.11</version>
  46.             <scope>test</scope>
  47.         </dependency>
  48.         <dependency>
  49.             <groupId>javax.servlet</groupId>
  50.             <artifactId>javax.servlet-api</artifactId>
  51.             <version>3.0.1</version>
  52.             <!-- 只在編譯時和測試時執行 -->
  53.             <scope>provided</scope>
  54.         </dependency>
  55.         <!-- spring的jar包 start -->
  56.         <dependency>
  57.             <groupId>org.springframework</groupId>
  58.             <artifactId>spring-core</artifactId>
  59.             <version>${spring.version}</version>
  60.         </dependency>
  61.         <dependency>
  62.             <groupId>org.springframework</groupId>
  63.             <artifactId>spring-web</artifactId>
  64.             <version>${spring.version}</version>
  65.         </dependency>
  66.         <dependency>
  67.             <groupId>org.springframework</groupId>
  68.             <artifactId>spring-oxm</artifactId>
  69.             <version>${spring.version}</version>
  70.         </dependency>
  71.         <dependency>
  72.             <groupId>org.springframework</groupId>
  73.             <artifactId>spring-tx</artifactId>
  74.             <version>${spring.version}</version>
  75.         </dependency>
  76.         <dependency>
  77.             <groupId>org.springframework</groupId>
  78.             <artifactId>spring-jdbc</artifactId>
  79.             <version>${spring.version}</version>
  80.         </dependency>
  81.         <dependency>
  82.             <groupId>org.springframework</groupId>
  83.             <artifactId>spring-webmvc</artifactId>
  84.             <version>${spring.version}</version>
  85.         </dependency>
  86.         <dependency>
  87.             <groupId>org.springframework</groupId>
  88.             <artifactId>spring-aop</artifactId>
  89.             <version>${spring.version}</version>
  90.         </dependency>
  91.         <dependency>
  92.             <groupId>org.springframework</groupId>
  93.             <artifactId>spring-context-support</artifactId>
  94.             <version>${spring.version}</version>
  95.         </dependency>
  96.         <dependency>
  97.             <groupId>org.springframework</groupId>
  98.             <artifactId>spring-test</artifactId>
  99.             <version>${spring.version}</version>
  100.         </dependency>
  101.         <!-- spring的jar包 end -->
  102.         <!-- 事務 start -->
  103.         <dependency>
  104.             <groupId>org.aspectj</groupId>
  105.             <artifactId>aspectjweaver</artifactId>
  106.             <version>${aspectj.version}</version>
  107.         </dependency>
  108.         <dependency>
  109.             <groupId>org.aspectj</groupId>
  110.             <artifactId>aspectjrt</artifactId>
  111.             <version>${aspectj.version}</version>
  112.         </dependency>
  113.         <!-- 事務 end -->
  114.         <!-- mybatis核心包 -->
  115.         <dependency>
  116.             <groupId>org.mybatis</groupId>
  117.             <artifactId>mybatis</artifactId>
  118.             <version>${mybatis.version}</version>
  119.         </dependency>
  120.         <!-- mybatis/spring包 -->
  121.         <dependency>
  122.             <groupId>org.mybatis</groupId>
  123.             <artifactId>mybatis-spring</artifactId>
  124.             <version>1.2.2</version>
  125.         </dependency>
  126.         <!-- hibernate驗證 -->
  127.         <dependency>
  128.             <groupId>org.hibernate</groupId>
  129.             <artifactId>hibernate-validator</artifactId>
  130.             <version>5.3.4.Final</version>
  131.         </dependency>
  132.         <!-- 匯入java ee jar 包 -->
  133.         <dependency>
  134.             <groupId>javax</groupId>
  135.             <artifactId>javaee-api</artifactId>
  136.             <version>7.0</version>
  137.         </dependency>
  138.         <!-- 匯入Mysql資料庫連結jar包 -->
  139.         <dependency>
  140.             <groupId>mysql</groupId>
  141.             <artifactId>mysql-connector-java</artifactId>
  142.             <version>5.1.30</version>
  143.         </dependency>
  144.         <!-- JSTL標籤類 -->
  145.         <dependency>
  146.             <groupId>jstl</groupId>
  147.             <artifactId>jstl</artifactId>
  148.             <version>1.2</version>
  149.         </dependency>
  150.         <!-- 日誌檔案管理包 -->
  151.         <!-- log start -->
  152.         <dependency>
  153.             <groupId>log4j</groupId>
  154.             <artifactId>log4j</artifactId>
  155.             <version>${log4j.version}</version>
  156.         </dependency>
  157.         <!-- 格式化物件,方便輸出日誌 -->
  158.         <dependency>
  159.             <groupId>com.alibaba</groupId>
  160.             <artifactId>fastjson</artifactId>
  161.             <version>1.2.17</version>
  162.         </dependency>
  163.         <dependency>
  164.             <groupId>org.slf4j</groupId>
  165.             <artifactId>slf4j-api</artifactId>
  166.             <version>${slf4j.version}</version>
  167.         </dependency>
  168.         <dependency>
  169.             <groupId>org.slf4j</groupId>
  170.             <artifactId>slf4j-log4j12</artifactId>
  171.             <version>${slf4j.version}</version>
  172.         </dependency>
  173.         <!-- log end -->
  174.         <!-- 分頁外掛 -->
  175.         <dependency>
  176.             <groupId>com.github.pagehelper</groupId>
  177.             <artifactId>pagehelper</artifactId>
  178.             <version>4.2.0</version>
  179.         </dependency>
  180.         <!-- pinyin4j -->
  181.         <dependency>
  182.             <groupId>com.belerweb</groupId>
  183.             <artifactId>pinyin4j</artifactId>
  184.             <version>2.5.0</version>
  185.         </dependency>
  186.         <!-- freemarker -->
  187.         <dependency>
  188.             <groupId>org.freemarker</groupId>
  189.             <artifactId>freemarker</artifactId>
  190.             <version>2.3.23</version>
  191.         </dependency>
  192.         <!-- 阿里的資料來源 -->
  193.         <dependency>
  194.             <groupId>com.alibaba</groupId>
  195.             <artifactId>druid</artifactId>
  196.             <version>1.0.26</version>
  197.         </dependency>
  198.         <!-- 阿里dubbo -->
  199.         <dependency>
  200.             <groupId>com.alibaba</groupId>
  201.             <artifactId>dubbo</artifactId>
  202.             <version>${dubbo.version}</version>
  203.         </dependency>
  204.         <!-- google java library -->
  205.         <dependency>
  206.             <groupId>com.google.guava</groupId>
  207.             <artifactId>guava</artifactId>
  208.             <version>18.0</version>
  209.         </dependency>
  210.         <!-- 映入JSON -->
  211.         <dependency>
  212.             <groupId>org.codehaus.jackson</groupId>
  213.             <artifactId>jackson-mapper-asl</artifactId>
  214.             <version>1.9.13</version>
  215.         </dependency>
  216.         <!-- apache的工具類 start -->
  217.         <dependency>
  218.             <groupId>org.apache.commons</groupId>
  219.             <artifactId>commons-lang3</artifactId>
  220.             <version>3.3.2</version>
  221.         </dependency>
  222.         <dependency>
  223.             <groupId>commons-collections</groupId>
  224.             <artifactId>commons-collections</artifactId>
  225.             <version>3.2.1</version>
  226.         </dependency>
  227.         <dependency>
  228.             <groupId>commons-beanutils</groupId>
  229.             <artifactId>commons-beanutils</artifactId>
  230.             <version>1.9.2</version>
  231.             <exclusions>
  232.                 <exclusion>
  233.                     <artifactId>commons-logging</artifactId>
  234.                     <groupId>commons-logging</groupId>
  235.                 </exclusion>
  236.             </exclusions>
  237.         </dependency>
  238.         <dependency>
  239.             <groupId>commons-io</groupId>
  240.             <artifactId>commons-io</artifactId>
  241.             <version>2.4</version>
  242.         </dependency>
  243.         <dependency>
  244.             <groupId>commons-codec</groupId>
  245.             <artifactId>commons-codec</artifactId>
  246.             <version>1.9</version>
  247.         </dependency>
  248.         <dependency>
  249.             <groupId>org.apache.httpcomponents</groupId>
  250.             <artifactId>httpclient</artifactId>
  251.             <version>${httpcomponents.version}</version>
  252.         </dependency>
  253.         <dependency>
  254.             <groupId>org.apache.httpcomponents</groupId>
  255.             <artifactId>httpcore</artifactId>
  256.             <version>${httpcomponents.version}</version>
  257.         </dependency>
  258.         <dependency>
  259.             <groupId>org.apache.httpcomponents</groupId>
  260.             <artifactId>httpmime</artifactId>
  261.             <version>${httpcomponents.version}</version>
  262.         </dependency>
  263.         <dependency>
  264.             <groupId>org.apache.httpcomponents</groupId>
  265.             <artifactId>httpclient-cache</artifactId>
  266.             <version>${httpcomponents.version}</version>
  267.         </dependency>
  268.         <!-- apache的工具類 end -->
  269.         <!-- 上傳元件包 -->
  270.         <dependency>
  271.             <groupId>commons-fileupload</groupId>
  272.             <artifactId>commons-fileupload</artifactId>
  273.             <version>1.3.1</version>
  274.         </dependency>
  275.         <!-- log4jdbc -->
  276.         <dependency>
  277.             <groupId>com.googlecode.log4jdbc</groupId>
  278.             <artifactId>log4jdbc</artifactId>
  279.             <version>1.2</version>
  280.             <scope>runtime</scope>
  281.         </dependency>
  282.     </dependencies>
  283.     <build>
  284.         <finalName>buoumall</finalName>
  285.         <plugins>
  286.             <plugin>
  287.                 <groupId>org.apache.maven.plugins</groupId>
  288.                 <artifactId>maven-compiler-plugin</artifactId>
  289.                 <configuration>
  290.                     <source>1.8</source>
  291.                     <target>1.8</target>
  292.                 </configuration>
  293.             </plugin>
  294.         </plugins>
  295.         <resources>
  296.             <resource>
  297.                 <directory>src/main/resources</directory>
  298.                 <filtering>false</filtering>
  299.             </resource>
  300.             <resource>
  301.                 <directory>src/main/conf/dev</directory>
  302.                 <filtering>false</filtering>
  303.             </resource>
  304.         </resources>
  305.     </build>
  306. </project>
3.web.xml的配置
  1. <?xmlversion="1.0"encoding="UTF-8"?>
  2. <web-appxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3.     xmlns="http://java.sun.com/xml/ns/javaee"
  4.     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
  5.     id="WebApp_ID"version="3.0">
  6.     <display-name>buoumall-business</display-name>
  7.     <!-- Spring context startup Spring的初始化   -->