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

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

相关推荐
Slow菜鸟4 小时前
AI学习篇(五) | awesome-design-md 使用说明
人工智能·学习
ZC跨境爬虫5 小时前
跟着 MDN 学 HTML day_9:(信件语义标记)
前端·css·笔记·ui·html
码点滴5 小时前
什么时候用 DeepSeek V4,而不是 GPT-5/Claude/Gemini?
人工智能·gpt·架构·大模型·deepseek
heimeiyingwang5 小时前
【架构实战】状态机架构:订单/工单状态流转设计
观察者模式·架构·wpf
狐狐生风5 小时前
LangChain 向量存储:Chroma、FAISS
人工智能·python·学习·langchain·faiss·agentai
狐狐生风5 小时前
LangChain RAG 基础
人工智能·python·学习·langchain·rag·agentai
rKWP8gKv76 小时前
Java微服务性能监控:Prometheus与Grafana集成方案
java·微服务·prometheus
小江的记录本6 小时前
【Kafka核心】架构模型:Producer、Broker、Consumer、Consumer Group、Topic、Partition、Replica
java·数据库·分布式·后端·搜索引擎·架构·kafka
一切皆是因缘际会7 小时前
AI数字分身的底层原理:破解意识、自我与人格复刻的核心难题
大数据·人工智能·ai·架构
努力努力再努力FFF8 小时前
医生对AI辅助诊断感兴趣,作为临床人员该怎么了解和学习?
人工智能·学习