微服务拆分-拆分购物车服务

发布于:2025-03-09 ⋅ 阅读:(104) ⋅ 点赞:(0)

新建一个cart-service模块,实现购物车服务。

 导入item-service模块的依赖。

    <dependencies>
        <!--common-->
        <dependency>
            <groupId>com.heima</groupId>
            <artifactId>hm-common</artifactId>
            <version>1.0.0</version>
        </dependency>
        <!--web-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!--数据库-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <!--mybatis-->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>2.1.1</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>2.1.1</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>
    <build>
        <finalName>${project.artifactId}</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

 新建包并且准备一个启动类。

 拷贝item-service模块的配置文件进行修改,每一个微服务都有自己的数据库。

将hm-service模块里面有关购物车的代码拷贝到cart-service模块中去。 做了拆分该模块获取不到其他模块的数据库信息,所以将该模块的功能注释起来,加上TODO以便后期处理。

 虽然业务不完整但是可以运行,我们希望它激活的是local不是dev配置文件,因为这样它读取的才是我们虚拟机MySQL的ip地址。

 


网站公告

今日签到

点亮在社区的每一天
去签到