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

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

导入item-service模块的依赖。

java 复制代码
    <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地址。

相关推荐
Web3&Basketball22 分钟前
CRM Agent 后训练实战:3 倍更少错误
python·架构·大模型·agent·推理
益达丫28 分钟前
Socket编程揭秘:端口、IP与进程通信的底层逻辑
linux·笔记
无敌贵点大王2 小时前
RTThread学习记录11——RT-Thread 设备模型吃透:UART/ADC/PWM/PIN 到底有什么区别?
c语言·stm32·学习·链表
是翎3 小时前
深度长文|2026产品经理AI实践手册
人工智能·深度学习·学习·自然语言处理·数据挖掘
Linux-lucky3 小时前
32-38-Linux学习之旅之MySQL综合
linux·运维·学习·mysql·ubuntu
知识分享小能手4 小时前
C++ 学习教程,从入门到精通,C++ 入门知识 — 完整知识点(1)
开发语言·c++·学习
ting94520005 小时前
深度拆解Enter Pro AI原生开发平台:从底层架构到企业级落地技术实践
人工智能·架构·ai-native
这个DBA有点耶6 小时前
数据库集群与分布式架构:三条技术路线对比、金仓KES RAC实测数据与决策框架
数据库·程序员·架构
马可家的菠萝6 小时前
你收藏的资料,有多少真的被你第二次打开过?
笔记·知识管理·效率提升·个人知识库
春天花会开1316 小时前
Supabase 自部署 Edge Functions 超时从 60s 延长到 360s 完整复盘
运维·云原生