maven管理的多模块spring boot个性化推荐商城项目

spring boot项目搭建

  • idea搭建主项目
    选择spring项目构建,和官网构建其实是一样的
    在这里插入图片描述
    填写相关的名称在这里插入图片描述
    选择你需要的依赖(可以先不填,等到分完模块后填)
    在这里插入图片描述
  • 子模块的搭建
    在这里插入图片描述
    其他模块一样的配置

修改主pom和子模块pom

总体意思是让主pom使用dependencyManagement来管理所有三方库和子模块的依赖版本

  • 主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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <!--maven父包管理使用pom-->
        <packaging>pom</packaging>
    
        <!--模块-->
        <modules>
            <!--控制层-->
            <module>wmall-web</module>
            <!--业务逻辑层-->
            <module>wmall-service</module>
            <!--数据库操作层-->
            <module>wmall-dao</module>
            <!--公共工具模块-->
            <module>wmall-common</module>
            <!--数据库模型层-->
            <module>wmall-model</module>
        </modules>
    
        <!--spring boot父类-->
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.1.9.RELEASE</version>
            <relativePath/>
        </parent>
    
        <!--主项目信息-->
        <groupId>com.actstrady</groupId>
        <artifactId>wmall</artifactId>
        <version>1.0.0-SNAPSHOT</version>
        <name>wmall</name>
        <description>personalized recommendation mall</description>
    
        <properties>
            <!--定义所有用到的依赖的版本-->
            <java.version>11</java.version>
        </properties>
        <!--使用主pom管理全部模块依赖的方式进行管理,
        父模块只提供版本定义,所以子模块需要用的时候自己引用,只是不需要写版本号-->
        <dependencyManagement>
            <dependencies>
                <!--子模块的版本交给主模块处理-->
                <dependency>
                    <groupId>com.actstrady</groupId>
                    <artifactId>wmall-web</artifactId>
                    <version>${project.version}</version>
                </dependency>
                <dependency>
                    <groupId>com.actstrady</groupId>
                    <artifactId>wmall-service</artifactId>
                    <version>${project.version}</version>
                </dependency>
                <dependency>
                    <groupId>com.actstrady</groupId>
                    <artifactId>wmall-dao</artifactId>
                    <version>${project.version}</version>
                </dependency>
                <dependency>
                    <groupId>com.actstrady</groupId>
                    <artifactId>wmall-model</artifactId>
                    <version>${project.version}</version>
                </dependency>
                <dependency>
                    <groupId>com.actstrady</groupId>
                    <artifactId>wmall-common</artifactId>
                    <version>${project.version}</version>
                </dependency>
            </dependencies>
        </dependencyManagement>
    </project>
    
  • dao层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>wmall</artifactId>
            <groupId>com.actstrady</groupId>
            <version>1.0.0-SNAPSHOT</version>
        </parent>
        <modelVersion>4.0.0</modelVersion>
        <artifactId>wmall-dao</artifactId>
    
        <dependencies>
            <!--dao依赖于model-->
            <dependency>
                <groupId>com.actstrady</groupId>
                <artifactId>wmall-model</artifactId>
            </dependency>
        </dependencies>
    </project>
    
  • service层dao
    <?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>wmall</artifactId>
            <groupId>com.actstrady</groupId>
            <version>1.0.0-SNAPSHOT</version>
        </parent>
        <modelVersion>4.0.0</modelVersion>
        <artifactId>wmall-service</artifactId>
    
        <dependencies>
            <!--service依赖于dao-->
            <dependency>
                <groupId>com.actstrady</groupId>
                <artifactId>wmall-dao</artifactId>
            </dependency>
        </dependencies>
    </project>
    
  • web层的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>wmall</artifactId>
            <groupId>com.actstrady</groupId>
            <version>1.0.0-SNAPSHOT</version>
        </parent>
        <modelVersion>4.0.0</modelVersion>
    
        <artifactId>wmall-web</artifactId>
        <dependencies>
            <!--web依赖于service-->
            <dependency>
                <groupId>com.actstrady</groupId>
                <artifactId>wmall-service</artifactId>
            </dependency>
    
            <!--spring boot reactor web提供的依赖-->
            <!--web flux-->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-webflux</artifactId>
            </dependency>
            <!--spring boot test依赖-->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
            <!--reactor的测试依赖-->
            <dependency>
                <groupId>io.projectreactor</groupId>
                <artifactId>reactor-test</artifactId>
                <scope>test</scope>
            </dependency>
        </dependencies>
    </project>
    
  • 其他两个pom不用修改,他们没什么依赖关系,都是其他依赖他们

项目启动测试(写一个resful规范的User)

尝试使用spring5的新引入的响应式编程来实现,即Web Reactive,包含Spring WebFlux与springboot的spring Reactive web来快速构建项目,目前项目暂时搁置,具体的技术比较新,比如spring-data-r2dbc,就是实现关系型数据库的非阻塞异步,spring官方提供的解决方案。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章