Spring Cloud微服务之搭建service_user模块(三)

一、搭建service_user模块

在父工程service模块下面创建子模块service_user,也是一个Maven工程,此模块专门用来做用户的CRUD操作实现。

注意:当我们创建service_user模块时,这个节点名称可能不对,记得改成它上一个父工程的节点名称,service才是service_user的父工程。

在这里插入图片描述

创建UserController控制器,进行测试

在这里插入图片描述

@RestController       //返回json数据
@RequestMapping(value = "user")
public class UserController {

    @GetMapping(value = "list")
    public String index(){
        return "hello Spring Cloud!";
    }
}

创建Spring Boot启动类

/**
 * 启动类
 */
@SpringBootApplication
@ComponentScan(basePackages = {"com.itydf"})
public class UserApplication {

    public static void main(String[] args) {
        SpringApplication.run(UserApplication.class, args);
    }
}
编写全局配置文件

因为在service模块中,我们引入了MySQL依赖,所以此时我们需要配置一下MySQL,否则启动会报错,找不到连接。
在这里插入图片描述application.properties
先随便在本地创建一个数据库。

# 服务端口
server.port=9901

# 环境设置:dev、test、prod
spring.profiles.active=dev

# mysql数据库连接
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/你的数据库地址?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8
spring.datasource.username=root
spring.datasource.password=123456

#返回json的全局时间格式
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8

启动service_user模块,输入地址测试在这里插入图片描述

成功了,此时基本的结构我们就搭建完成了。

这里说一下整个结构:一定要懂这个依赖关系。

  • parent父工程,下面有service模块,service下面有service_user模块。
  • service可以使用parent的公共依赖,service_user又可以使用service的依赖。
  • 说明了Spring Cloud的依赖可以相互依赖。

后续文章,更新中。。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

DT辰白

你的鼓励是我创作的源泉

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值