为了账号安全,请及时绑定邮箱和手机立即绑定

【九月打卡】第三天 后端服务构建,聚合工程子模块建立

标签:
Java

课程名称:Spring Cloud 进阶 Alibaba 微服务体系自媒体实战
课程章节: 第2章 架构后端项目
主讲老师: 风间影月

课程内容

上节课程当中,学习了聚合工程的建立。但是那个只是一个父级工程,他不承载任何业务的实现(类比与企业老板)。

但是,一个项目中不可能没有具体的业务实现。所以需要在聚合工程下建立诸多的子模块。

在之前的课程当中,就有提过。本多媒体项目当中,会建立公共模块、model模块、API接口模块等。

子模块分为:

  • imooc-news-dev-common:

<!--
    imooc-news-common:
    通用工程
    包含了一些工具类,枚举类,封装的公共方法
-->
  • imooc-news-dev-model

<!--
	imooc-news-model:
	模型工程,所有子工程以及微服务中所涉及到模型实体都在此管理
	可以包含一些 *Pojo,*Bean 或 *Entity,比如:vo, bo, dto等
-->

此处,还需要向上依赖common模块里面的内容。具体代码如下:

<dependency>
	<groupId>com.imooc</groupId>
	<artifactId>imooc-news-common</artifactId>
	<version>1.0-SNAPSHOT</version>
</dependency>
  • imooc-news-dev-service-api

<!--
	imooc-news-service-api:
	接口工程,集中管理所有controller中的接口,为了更好的统一管理微服务
-->
<dependency>
	<groupId>com.imooc</groupId>
	<artifactId>imooc-news-model</artifactId>
	<version>1.0-SNAPSHOT</version>
</dependency>
  • imooc-news-dev-service-user

<!-- 	imooc-news-service-user: 	用户服务,用户相关业务在此微服务工程中实现 
包含:用户登录,用户注册,用户信息查询等 --> 
<dependency> 
  <groupId>com.imooc</groupId> 
  <artifactId>imooc-news-service-api</artifactId> 
  <version>1.0-SNAPSHOT</version> 
</dependency>


构建HelloController进行测试

<!-- SpringBoot -->
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-configuration-processor</artifactId>
</dependency>

@RestController
public class HelloController {
    @GetMapping("/hello")
    public Object hello() {
        return IMOOCJSONResult.ok("Hello World~");
    }
}

课程收获

  • Maven的依赖层级可以逐级传递的。

    • 项目当中就是通过Common→model→api逐级进行依赖传递的。

  • 在聚合工程里,父级工程的parent设置了springboot工程以后,子工程还需要引用具体的依赖。


课程截图

https://img1.sycdn.imooc.com//6319fa4d000132c327181554.jpg

https://img1.sycdn.imooc.com//6319fa5c0001065c27321570.jpg

https://img1.sycdn.imooc.com//6319fa7400011de426441522.jpg


点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
JAVA开发工程师
手记
粉丝
1
获赞与收藏
2

关注作者,订阅最新文章

阅读免费教程

  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消