Springcloud从零开始---Service业务模块(三)

上篇:Springcloud从零开始---Zuul(二)-CSDN博客

Service模块是客户端模块,用户编写业务逻辑代码和功能实现。前端请求发送到Zuul网关再有网关发送到Service服务,可以是系统的安全性提升。

开始继上篇Springcloud从零开始---Zuul(二)-CSDN博客 新建业务Service模块

1,继续在父工程下新建:New-Module

2,Maven--next

 3,填写ArtifactId即项目名称  next

4, 直接Finish

5,新建成功

 

6,添加依赖

代码

<dependencies>
        <!--web起步依赖-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!-- Eureka客户端 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>

        <!--通用mapper起步依赖-->
        <dependency>
            <groupId>tk.mybatis</groupId>
            <artifactId>mapper-spring-boot-starter</artifactId>
            <version>2.0.4</version>
        </dependency>
        <!--MySQL数据库驱动-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <!--mybatis分页插件-->
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
            <version>1.2.3</version>
        </dependency>
</dependencies>

 7,配置appcation.yml核心文件

代码

server:
  port: 7777
spring:
  application:
    name: service-study
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/spring?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
    username: root
    password: root
eureka:
  client:
    service-url:
      defaultZone: http://localhost:8888/eureka

8,新建启动类 ServiceApplication

代码

package com.zwj;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;

 
@SpringBootApplication
@EnableEurekaClient
public class ServiceApplication {

    public static void main(String[] args) {
        SpringApplication.run(ServiceApplication.class, args);
    }
}

 9,启动ServiceApplication启动类,单击右键点Run(前提必须先启动,Eureka启动类,其次Zuul启动类)

10,浏览器访问:http://localhost:8888/

Eureka注册中心出现service-study项目名称说明已经成功了。

到此简单的springcloud微服务搭建完毕,在service模块里面可以先业务逻辑代码,如果还需要更多类似service_study模块,可以照这个步骤继续添加,注意端口号不要重复即可,每个业务模块核心配置applicant.yml 中也可以连接不同数据库,互不影响。每新建一个模块,Eureka注册中心都可以查到它的信息,切记Eureka模块先启动,其次Zuul模块,最后是业务模块。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值