b2cTest分佈式項目搭建流程:html
分佈式項目優點:java
1.創建聚合工程-pom,b2cTest-parent;mysql
1.修改pom.xmlgit
1.集中定義依賴版本號github
1 <!-- 集中定義依賴版本號 --> 2 <properties> 3 <junit.version>4.12</junit.version> 4 <spring.version>4.1.3.RELEASE</spring.version> 5 <mybatis.version>3.2.8</mybatis.version> 6 <mybatis.spring.version>1.2.2</mybatis.spring.version> 7 <mybatis.paginator.version>1.2.15</mybatis.paginator.version> 8 <mysql.version>5.1.32</mysql.version> 9 <slf4j.version>1.6.4</slf4j.version> 10 <jackson.version>2.4.2</jackson.version> 11 <druid.version>1.0.9</druid.version> 12 <httpclient.version>4.3.5</httpclient.version> 13 <jstl.version>1.2</jstl.version> 14 <servlet-api.version>2.5</servlet-api.version> 15 <jsp-api.version>2.0</jsp-api.version> 16 <joda-time.version>2.5</joda-time.version> 17 <commons-lang3.version>3.3.2</commons-lang3.version> 18 <commons-io.version>1.3.2</commons-io.version> 19 <commons-net.version>3.3</commons-net.version> 20 <pagehelper.version>5.0.0</pagehelper.version> 21 <jsqlparser.version>0.9.1</jsqlparser.version> 22 <commons-fileupload.version>1.3.1</commons-fileupload.version> 23 <jedis.version>2.7.2</jedis.version> 24 <solrj.version>4.10.3</solrj.version> 25 </properties>
2.導入jar包web
<dependencyManagement> <dependencies> <!-- 時間操做組件 --> <dependency> <groupId>joda-time</groupId> <artifactId>joda-time</artifactId> <version>${joda-time.version}</version> </dependency> <!-- Apache工具組件 --> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> <version>${commons-lang3.version}</version> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-io</artifactId> <version>${commons-io.version}</version> </dependency> <dependency> <groupId>commons-net</groupId> <artifactId>commons-net</artifactId> <version>${commons-net.version}</version> </dependency> <!-- Jackson Json處理工具包 --> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>${jackson.version}</version> </dependency> <!-- httpclient --> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>${httpclient.version}</version> </dependency> <!-- 單元測試 --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>${junit.version}</version> <scope>test</scope> </dependency> <!-- 日誌處理 --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>${slf4j.version}</version> </dependency> <!-- Mybatis --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>${mybatis.version}</version> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version>${mybatis.spring.version}</version> </dependency> <dependency> <groupId>com.github.miemiedev</groupId> <artifactId>mybatis-paginator</artifactId> <version>${mybatis.paginator.version}</version> </dependency> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> <version>${pagehelper.version}</version> </dependency> <!-- MySql --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>${mysql.version}</version> </dependency> <!-- 鏈接池 --> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>${druid.version}</version> </dependency> <!-- Spring --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</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-jdbc</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aspects</artifactId> <version>${spring.version}</version> </dependency> <!-- JSP相關 --> <dependency> <groupId>jstl</groupId> <artifactId>jstl</artifactId> <version>${jstl.version}</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>${servlet-api.version}</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jsp-api</artifactId> <version>${jsp-api.version}</version> <scope>provided</scope> </dependency> <!-- 文件上傳組件 --> <dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> <version>${commons-fileupload.version}</version> </dependency> <!-- Redis客戶端 --> <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>${jedis.version}</version> </dependency> <!-- solr客戶端 --> <dependency> <groupId>org.apache.solr</groupId> <artifactId>solr-solrj</artifactId> <version>${solrj.version}</version> </dependency> </dependencies> </dependencyManagement>
3.build插件redis
1 <build> 2 <finalName>${project.artifactId}</finalName> 3 <plugins> 4 <!-- 資源文件拷貝插件 --> 5 <plugin> 6 <groupId>org.apache.maven.plugins</groupId> 7 <artifactId>maven-resources-plugin</artifactId> 8 <version>2.7</version> 9 <configuration> 10 <encoding>UTF-8</encoding> 11 </configuration> 12 </plugin> 13 <!-- java編譯插件 --> 14 <plugin> 15 <groupId>org.apache.maven.plugins</groupId> 16 <artifactId>maven-compiler-plugin</artifactId> 17 <version>3.2</version> 18 <configuration> 19 <source>1.8</source> 20 <target>1.8</target> 21 <encoding>UTF-8</encoding> 22 </configuration> 23 </plugin> 24 </plugins> 25 <pluginManagement> 26 <plugins> 27 <!-- 配置Tomcat插件 --> 28 <plugin> 29 <groupId>org.apache.tomcat.maven</groupId> 30 <artifactId>tomcat7-maven-plugin</artifactId> 31 <version>2.2</version> 32 </plugin> 33 </plugins> 34 </pluginManagement> 35 </build>
2.創建工具包-jar,b2cTest-common,繼承b2cTest-parent;spring
1.修改pom.xmlsql
1 <!-- jar包的依賴 --> 2 <dependencies> 3 <!-- 時間操做組件 --> 4 <dependency> 5 <groupId>joda-time</groupId> 6 <artifactId>joda-time</artifactId> 7 </dependency> 8 <!-- Apache工具組件 --> 9 <dependency> 10 <groupId>org.apache.commons</groupId> 11 <artifactId>commons-lang3</artifactId> 12 </dependency> 13 <dependency> 14 <groupId>org.apache.commons</groupId> 15 <artifactId>commons-io</artifactId> 16 </dependency> 17 <dependency> 18 <groupId>commons-net</groupId> 19 <artifactId>commons-net</artifactId> 20 </dependency> 21 <!-- Jackson Json處理工具包 --> 22 <dependency> 23 <groupId>com.fasterxml.jackson.core</groupId> 24 <artifactId>jackson-databind</artifactId> 25 </dependency> 26 <!-- httpclient --> 27 <dependency> 28 <groupId>org.apache.httpcomponents</groupId> 29 <artifactId>httpclient</artifactId> 30 </dependency> 31 <!-- 單元測試 --> 32 <dependency> 33 <groupId>junit</groupId> 34 <artifactId>junit</artifactId> 35 <scope>test</scope> 36 </dependency> 37 <!-- 日誌處理 --> 38 <dependency> 39 <groupId>org.slf4j</groupId> 40 <artifactId>slf4j-log4j12</artifactId> 41 </dependency> 42 </dependencies>
3.創建後臺管理工程-pom,b2cTest-managerapache
1.修改pom文件,加入工具包common依賴。
1 <!-- 依賴管理 --> 2 <dependencies> 3 <dependency> 4 <groupId>com.b2cTest</groupId> 5 <artifactId>b2cTest-common</artifactId> 6 <version>0.0.1-SNAPSHOT</version> 7 </dependency> 8 </dependencies>
2.創建後臺管理工程-jar,new maven module ,b2cTest-manager-pojo,pojo是對象模塊,無需依賴.
3.創建後臺管理工程-jar,new maven module,b2cTest-manager-mapper,mapper依賴pjo
添加依賴和jar包
1 <dependencies> 2 <!-- 添加pojo依賴 --> 3 <dependency> 4 <groupId>com.b2cTest</groupId> 5 <artifactId>b2cTest-manager-pojo</artifactId> 6 <version>0.0.1-SNAPSHOT</version> 7 </dependency> 8 <!-- Mybatis --> 9 <dependency> 10 <groupId>org.mybatis</groupId> 11 <artifactId>mybatis</artifactId> 12 </dependency> 13 <dependency> 14 <groupId>org.mybatis</groupId> 15 <artifactId>mybatis-spring</artifactId> 16 </dependency> 17 <dependency> 18 <groupId>com.github.miemiedev</groupId> 19 <artifactId>mybatis-paginator</artifactId> 20 </dependency> 21 <dependency> 22 <groupId>com.github.pagehelper</groupId> 23 <artifactId>pagehelper</artifactId> 24 </dependency> 25 <!-- MySql --> 26 <dependency> 27 <groupId>mysql</groupId> 28 <artifactId>mysql-connector-java</artifactId> 29 </dependency> 30 <!-- 鏈接池 --> 31 <dependency> 32 <groupId>com.alibaba</groupId> 33 <artifactId>druid</artifactId> 34 </dependency> 35 </dependencies>
4.創建後臺管理工程-jar,new maven module,b2cTest-manager-service,service依賴mapper
添加依賴和jar包
1 <dependencies> 2 <!-- 添加mapper依賴 --> 3 <dependency> 4 <groupId>com.b2cTest</groupId> 5 <artifactId>b2cTest-manager-mapper</artifactId> 6 <version>0.0.1-SNAPSHOT</version> 7 </dependency> 8 <!-- Spring --> 9 <dependency> 10 <groupId>org.springframework</groupId> 11 <artifactId>spring-context</artifactId> 12 </dependency> 13 <dependency> 14 <groupId>org.springframework</groupId> 15 <artifactId>spring-beans</artifactId> 16 </dependency> 17 <dependency> 18 <groupId>org.springframework</groupId> 19 <artifactId>spring-webmvc</artifactId> 20 </dependency> 21 <dependency> 22 <groupId>org.springframework</groupId> 23 <artifactId>spring-jdbc</artifactId> 24 </dependency> 25 <dependency> 26 <groupId>org.springframework</groupId> 27 <artifactId>spring-aspects</artifactId> 28 </dependency> 29 </dependencies>
5.創建後臺管理工程-war,new maven module,b2cTest-manager-controller,controller依賴service,web層須要使用war包
1.添加依賴和jar包
1 <dependencies> 2 <!-- 添加service依賴 --> 3 <dependency> 4 <groupId>com.b2cTest</groupId> 5 <artifactId>b2cTest-manager-servicer</artifactId> 6 <version>0.0.1-SNAPSHOT</version> 7 </dependency> 8 <!-- JSP相關 --> 9 <dependency> 10 <groupId>jstl</groupId> 11 <artifactId>jstl</artifactId> 12 </dependency> 13 <dependency> 14 <groupId>javax.servlet</groupId> 15 <artifactId>servlet-api</artifactId> 16 <scope>provided</scope> 17 </dependency> 18 <dependency> 19 <groupId>javax.servlet</groupId> 20 <artifactId>jsp-api</artifactId> 21 <scope>provided</scope> 22 </dependency> 23 <!-- 文件上傳組件 --> 24 <dependency> 25 <groupId>commons-fileupload</groupId> 26 <artifactId>commons-fileupload</artifactId> 27 </dependency> 28 </dependencies>
2.創建/b2cTest-manager-controller/src/main/webapp/WEB-INF/web.xml
1 <?xml version="1.0" encoding="UTF-8"?> 2 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 3 xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 4 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 5 id="b2cTest" version="2.5"> 6 <display-name>b2cTest-manager</display-name> 7 <welcome-file-list> 8 <welcome-file>index.html</welcome-file> 9 <welcome-file>index.htm</welcome-file> 10 <welcome-file>index.jsp</welcome-file> 11 <welcome-file>default.html</welcome-file> 12 <welcome-file>default.htm</welcome-file> 13 <welcome-file>default.jsp</welcome-file> 14 </welcome-file-list> 15 16 </web-app>
6.在b2cTest-manager下pom.xml加入如下pom代碼,後使用maven 運行,clean tomcat7:run
1 <build> 2 <!-- 配置插件 --> 3 <plugins> 4 <plugin> 5 <groupId>org.apache.tomcat.maven</groupId> 6 <artifactId>tomcat7-maven-plugin</artifactId> 7 <configuration> 8 <port>8080</port> 9 <path>/</path> 10 </configuration> 11 </plugin> 12 </plugins> 13 </build>