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

新建一个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地址。

相关推荐
JMchen1234 分钟前
Jetpack 内核实战(八):组件整合——DataStore + Room 构建离线优先架构
架构·room·datastore·组件整合·android 开发架构·jetpack 实战
ltl32 分钟前
AI 原生架构:LLM 时代的系统重构
架构
ltl34 分钟前
边缘计算架构:算力下沉的设计挑战
架构
JouYY1 小时前
大模型底层学习(三)-从零训练一个 BPE 分词器
架构·llm·agent
Dawson Zhu2 小时前
工业世界模型——基于AI Agent+数学仿真架构
人工智能·架构·agi
Wang's Blog2 小时前
AI Agent白手起家52: 从零搭建钉钉智能助手——资源准备与核心架构实现
人工智能·架构·钉钉
GlueNa2SiO32 小时前
第十八章 Linux故障排查与恢复
linux·服务器·笔记·学习
jufeng13072 小时前
【系列:手搓自主 AI Agent:Hermes 架构原理剖析 · 第 1 篇】
人工智能·python·架构·agent
制造业的搬运工2 小时前
智能窗帘PCB低功耗设计方案:架构要点与设计建议
人工智能·科技·架构·制造·pcb工艺
weixin_431600442 小时前
NestJS 入门(3):Guard 如何挡住未登录请求?
前端·后端·学习·nest.js