电商项目模拟(二)——搭建框架
目录
4搭建框架
4.1父工程
4.2通用实体类模块
4.3通用数据访问模块
4.4通用工具类模块
4.5商家商品服务接口模块
4.6商家商品服务模块
4.7运营商管理后台
4.8商家管理后台
4搭建框架
4.1父工程
创建Maven工程sc-parent (POM) ,groupId 为com.sc ,artifactId 为sc-parent , 在pom.xml中添加锁定版本信息dependencyManagement与pluginManagement,以下模块均继承自此父工程;
4.2通用实体类模块
创建通用实体类模块-sc-pojo
4.3通用数据访问模块
创建通用数据访问模块sc-dao .添加依赖Mybatis和sc-pojo
1 <dependencies> 2 <!-- Mybatis --> 3 <dependency> 4 <groupId>org.mybatis</groupId> 5 <artifactId>mybatis</artifactId> 6 </dependency> 7 <dependency> 8 <groupId>org.mybatis</groupId> 9 <artifactId>mybatis-spring</artifactId> 10 </dependency> 11 <dependency> 12 <groupId>com.github.miemiedev</groupId> 13 <artifactId>mybatis-paginator</artifactId> 14 </dependency> 15 <!-- MySql --> 16 <dependency> 17 <groupId>mysql</groupId> 18 <artifactId>mysql-connector-java</artifactId> 19 </dependency> 20 <!-- 连接池 --> 21 <dependency> 22 <groupId>com.xx</groupId> 23 <artifactId>druid</artifactId> 24 </dependency> 25 <dependency> 26 <groupId>com.pinyougou</groupId> 27 <artifactId>sc-pojo</artifactId> 28 <version>0.0.1-SNAPSHOT</version> 29 </dependency> 30 </dependencies>
4.4通用工具类模块
创建通用工具类模块pinyougou-common
4.5商家商品服务接口模块
创建maven(jar)模块sc-sellergoods-interface , pom.xml添加依赖
1 <dependencies> 2 <dependency> 3 <groupId>com.sc</groupId> 4 <artifactId>sc-pojo</artifactId> 5 <version>0.0.1-SNAPSHOT</version> 6 </dependency> 7 </dependencies>
4.6商家商品服务模块
创建maven(war)模块sc-sellergoods-service ,pom.xml引入依赖
1 <dependencies> 2 <!-- Spring --> 3 <dependency> 4 <groupId>org.springframework</groupId> 5 <artifactId>spring-context</artifactId> 6 </dependency> 7 <dependency> 8 <groupId>org.springframework</groupId> 9 <artifactId>spring-beans</artifactId> 10 </dependency> 11 <dependency> 12 <groupId>org.springframework</groupId> 13 <artifactId>spring-webmvc</artifactId> 14 </dependency> 15 <dependency> 16 <groupId>org.springframework</groupId> 17 <artifactId>spring-jdbc</artifactId> 18 </dependency> 19 <dependency> 20 <groupId>org.springframework</groupId> 21 <artifactId>spring-aspects</artifactId> 22 </dependency> 23 <dependency> 24 <groupId>org.springframework</groupId> 25 <artifactId>spring-jms</artifactId> 26 </dependency> 27 <dependency> 28 <groupId>org.springframework</groupId> 29 <artifactId>spring-context-support</artifactId> 30 </dependency> 31 <dependency> 32 <groupId>org.springframework</groupId> 33 <artifactId>spring-test</artifactId> 34 </dependency> 35 <!-- dubbo相关 --> 36 <dependency> 37 <groupId>com.alibaba</groupId> 38 <artifactId>dubbo</artifactId> 39 </dependency> 40 <dependency> 41 <groupId>org.apache.zookeeper</groupId> 42 <artifactId>zookeeper</artifactId> 43 </dependency> 44 <dependency> 45 <groupId>com.github.sgroschupf</groupId> 46 <artifactId>zkclient</artifactId> 47 </dependency> 48 <dependency> 49 <groupId>junit</groupId> 50 <artifactId>junit</artifactId> 51 </dependency> 52 <dependency> 53 <groupId>com.alibaba</groupId> 54 <artifactId>fastjson</artifactId> 55 </dependency> 56 <dependency> 57 <groupId>javassist</groupId> 58 <artifactId>javassist</artifactId> 59 </dependency> 60 <dependency> 61 <groupId>commons-codec</groupId> 62 <artifactId>commons-codec</artifactId> 63 </dependency> 64 <dependency> 65 <groupId>javax.servlet</groupId> 66 <artifactId>servlet-api</artifactId> 67 <scope>provided</scope> 68 </dependency> 69 <dependency> 70 <groupId>com.pinyougou</groupId> 71 <artifactId>sc-common</artifactId> 72 <version>0.0.1-SNAPSHOT</version> 73 </dependency> 74 <dependency> 75 <groupId>com.pinyougou</groupId> 76 <artifactId>sc-dao</artifactId> 77 <version>0.0.1-SNAPSHOT</version> 78 </dependency> 79 <dependency> 80 <groupId>com.sc</groupId> 81 <artifactId>sc-sellergoods-interface</artifactId> 82 <version>0.0.1-SNAPSHOT</version> 83 </dependency> 84 </dependencies> 85 <build> 86 <plugins> 87 <!-- 配置Tomcat插件 --> 88 <plugin> 89 <groupId>org.apache.tomcat.maven</groupId> 90 <artifactId>tomcat7-maven-plugin</artifactId> 91 <configuration> 92 <path>/</path> 93 <port>9001</port> 94 </configuration> 95 </plugin> 96 </plugins> 97 </build> 98 </project>
4.7运营商管理后台
创建maven(war)模块sc-manager-web , pom.xml引入依赖
1 <dependencies> 2 <!-- Spring --> 3 <dependency> 4 <groupId>org.springframework</groupId> 5 <artifactId>spring-context</artifactId> 6 </dependency> 7 <dependency> 8 <groupId>org.springframework</groupId> 9 <artifactId>spring-beans</artifactId> 10 </dependency> 11 <dependency> 12 <groupId>org.springframework</groupId> 13 <artifactId>spring-webmvc</artifactId> 14 </dependency> 15 <dependency> 16 <groupId>org.springframework</groupId> 17 <artifactId>spring-jdbc</artifactId> 18 </dependency> 19 <dependency> 20 <groupId>org.springframework</groupId> 21 <artifactId>spring-aspects</artifactId> 22 </dependency> 23 <dependency> 24 <groupId>org.springframework</groupId> 25 <artifactId>spring-jms</artifactId> 26 </dependency> 27 <dependency> 28 <groupId>org.springframework</groupId> 29 <artifactId>spring-context-support</artifactId> 30 </dependency> 31 <dependency> 32 <groupId>org.springframework</groupId> 33 <artifactId>spring-test</artifactId> 34 </dependency> 35 <!-- dubbo相关 --> 36 <dependency> 37 <groupId>com.alibaba</groupId> 38 <artifactId>dubbo</artifactId> 39 </dependency> 40 <dependency> 41 <groupId>org.apache.zookeeper</groupId> 42 <artifactId>zookeeper</artifactId> 43 </dependency> 44 <dependency> 45 <groupId>com.github.sgroschupf</groupId> 46 <artifactId>zkclient</artifactId> 47 </dependency> 48 <dependency> 49 <groupId>junit</groupId> 50 <artifactId>junit</artifactId> 51 </dependency> 52 <dependency> 53 <groupId>com.alibaba</groupId> 54 <artifactId>fastjson</artifactId> 55 </dependency> 56 <dependency> 57 <groupId>javassist</groupId> 58 <artifactId>javassist</artifactId> 59 </dependency> 60 <dependency> 61 <groupId>commons-codec</groupId> 62 <artifactId>commons-codec</artifactId> 63 </dependency> 64 <dependency> 65 <groupId>javax.servlet</groupId> 66 <artifactId>servlet-api</artifactId> 67 <scope>provided</scope> 68 </dependency> 69 <dependency> 70 <groupId>com.sc</groupId> 71 <artifactId>sc-common</artifactId> 72 <version>0.0.1-SNAPSHOT</version> 73 </dependency> 74 <dependency> 75 <groupId>com.sc</groupId> 76 <artifactId>sc-sellergoods-interface</artifactId> 77 <version>0.0.1-SNAPSHOT</version> 78 </dependency> 79 </dependencies> 80 <build> 81 <plugins> 82 <!-- 配置Tomcat插件 --> 83 <plugin> 84 <groupId>org.apache.tomcat.maven</groupId> 85 <artifactId>tomcat7-maven-plugin</artifactId> 86 <configuration> 87 <path>/</path> 88 <port>9101</port> 89 </configuration> 90 </plugin> 91 </plugins> 92 </build>
4.8商家管理后台
构建web模块sc-shop-web 与运营商管理后台的构建方式类似。区别:
(1)定义tomcat的启动端口为9102
(2)springmvc.xml
1 <!-- 引用dubbo 服务 --> 2 <dubbo:application name="sc-shop-web" /> 3 <dubbo:registry address="zookeeper://192.168.xx.xx:8081"/> 4 <dubbo:annotation package="sc包名" />