购物网站模板站,比分网站怎么做,天猫网站是用什么技术做的,海南建设银行官方网站很抱歉#xff0c;我的疏忽#xff0c;说了这么久还没有给大家详细讲解过Spring Boot和Spring Cloud,那今天给大家详细讲解一下。
大家可以和下面这三篇博客一起看#xff1a;
1、Spring Boot 和 Spring Cloud 微服务开发实践详解https://blog.csdn.net/speaking_me/artic…很抱歉我的疏忽说了这么久还没有给大家详细讲解过Spring Boot和Spring Cloud,那今天给大家详细讲解一下。
大家可以和下面这三篇博客一起看
1、Spring Boot 和 Spring Cloud 微服务开发实践详解https://blog.csdn.net/speaking_me/article/details/143917383?spm1001.2014.3001.5502
2、Spring Boot 和 Spring Cloud 构建一个完整的微服务架构——在线购物系统
https://blog.csdn.net/speaking_me/article/details/143918281?spm1001.2014.3001.5502
3、当今最热门的微服务框架搭建讲解和微服务开发实战之点餐管理系统实战内附源代码详细讲解
https://blog.csdn.net/speaking_me/article/details/144005596?spm1001.2014.3001.5502
Spring Boot
1. 核心概念
Spring Boot 是一个用于创建独立的、生产级的Spring应用程序的框架。它旨在简化新Spring应用的初始搭建以及开发过程。Spring Boot的主要目标是减少开发时间和配置工作使开发者能够更快地构建应用。
2. 主要功能
自动配置: Spring Boot会根据添加的依赖自动配置Spring应用。例如如果你添加了Spring MVC依赖Spring Boot会自动配置一个嵌入式的Tomcat服务器。独立运行: Spring Boot应用可以被打包成一个可执行的JAR或WAR文件不需要外部的Servlet容器。内嵌服务器: 默认支持内嵌的Tomcat、Jetty和Undertow服务器。简化配置: 提供了默认的配置选项可以通过属性文件轻松覆盖这些默认值。健康检查和监控: 内置了Actuator模块提供了应用的健康检查、监控等端点。起步依赖: 提供了一系列的“起步依赖”Starter Dependencies简化了依赖管理。
3. 示例项目
下面是一个简单的Spring Boot应用示例
3.1 创建项目
使用Spring Initializr创建一个新的Spring Boot项目选择以下依赖
Spring WebSpring Data JPAMySQL DriverSpring Boot DevTools
3.2 pom.xml project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersiongroupIdcom.example/groupIdartifactIddemo/artifactIdversion1.0.0-SNAPSHOT/versionpackagingjar/packagingparentgroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-parent/artifactIdversion2.7.5/versionrelativePath/ !-- lookup parent from repository --/parentpropertiesjava.version11/java.version/propertiesdependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-data-jpa/artifactId/dependencydependencygroupIdmysql/groupIdartifactIdmysql-connector-java/artifactIdscoperuntime/scope/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-devtools/artifactIdscoperuntime/scopeoptionaltrue/optional/dependency/dependenciesbuildpluginsplugingroupIdorg.springframework.boot/groupIdartifactIdspring-boot-maven-plugin/artifactId/plugin/plugins/build
/project 3.3 application.properties spring.datasource.urljdbc:mysql://localhost:3306/demo?useSSLfalseserverTimezoneUTC
spring.datasource.usernameroot
spring.datasource.passwordroot
spring.jpa.hibernate.ddl-autoupdate
spring.jpa.show-sqltrue 3.4 实体类 User.java package com.example.demo.entity;import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;Entity
public class User {IdGeneratedValue(strategy GenerationType.IDENTITY)private Long id;private String name;private String email;// Getters and Setters
} 3.5 仓库接口 UserRepository.java package com.example.demo.repository;import com.example.demo.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;Repository
public interface UserRepository extends JpaRepositoryUser, Long {
} 3.6 服务类 UserService.java package com.example.demo.service;import com.example.demo.entity.User;
import com.example.demo.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;import java.util.List;
import java.util.Optional;Service
public class UserService {Autowiredprivate UserRepository userRepository;public ListUser getAllUsers() {return userRepository.findAll();}public OptionalUser getUserById(Long id) {return userRepository.findById(id);}public User saveUser(User user) {return userRepository.save(user);}public void deleteUser(Long id) {userRepository.deleteById(id);}
} 3.7 控制器 UserController.java package com.example.demo.controller;import com.example.demo.entity.User;
import com.example.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;import java.util.List;
import java.util.Optional;RestController
RequestMapping(/users)
public class UserController {Autowiredprivate UserService userService;GetMappingpublic ListUser getAllUsers() {return userService.getAllUsers();}GetMapping(/{id})public OptionalUser getUserById(PathVariable Long id) {return userService.getUserById(id);}PostMappingpublic User saveUser(RequestBody User user) {return userService.saveUser(user);}DeleteMapping(/{id})public void deleteUser(PathVariable Long id) {userService.deleteUser(id);}
} 3.8 启动类 DemoApplication.java package com.example.demo;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;SpringBootApplication
public class DemoApplication {public static void main(String[] args) {SpringApplication.run(DemoApplication.class, args);}
} Spring Cloud
1. 核心概念
Spring Cloud 是一个基于Spring Boot构建的微服务框架提供了一整套微服务解决方案包括服务注册与发现、配置管理、断路器、智能路由、微代理、控制总线、一次性令牌、全局锁、领导选举、分布式ID、集群状态管理等。
2. 主要功能
服务发现: 使用Eureka、Consul或Zookeeper等组件进行服务注册和发现。配置管理: 使用Config Server集中管理配置文件。断路器: 使用Hystrix实现断路器模式防止服务雪崩。API网关: 使用Zuul或Spring Cloud Gateway作为API网关统一处理外部请求。消息总线: 使用Spring Cloud Bus实现消息驱动的应用程序。分布式跟踪: 使用Sleuth和Zipkin进行分布式跟踪。
3. 示例项目
下面是一个简单的Spring Cloud项目示例包括服务发现、配置管理和API网关。
3.1 服务发现Eureka
3.1.1 创建 discovery-service 模块
在父项目的 modules 目录下创建 discovery-service 模块。
3.1.2 discovery-service 的 pom.xml project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersionparentgroupIdcom.example/groupIdartifactIdbook-management-system/artifactIdversion1.0.0-SNAPSHOT/version/parentartifactIddiscovery-service/artifactIddependenciesdependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-netflix-eureka-server/artifactId/dependency/dependencies
/project 3.1.3 discovery-service 的 application.yml server:port: 8761eureka:instance:hostname: localhostclient:register-with-eureka: falsefetch-registry: falseservice-url:defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/ 3.1.4 启动类 DiscoveryServiceApplication.java package com.example.discoveryservice;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;SpringBootApplication
EnableEurekaServer
public class DiscoveryServiceApplication {public static void main(String[] args) {SpringApplication.run(DiscoveryServiceApplication.class, args);}
} 3.2 配置中心Config Service
3.2.1 创建 config-service 模块
在父项目的 modules 目录下创建 config-service 模块。
3.2.2 config-service 的 pom.xml project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersionparentgroupIdcom.example/groupIdartifactIdbook-management-system/artifactIdversion1.0.0-SNAPSHOT/version/parentartifactIdconfig-service/artifactIddependenciesdependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-config-server/artifactId/dependency/dependencies
/project 3.2.3 config-service 的 application.yml server:port: 8888spring:application:name: config-servicecloud:config:server:git:uri: https://github.com/your-repo/config-repo.gitclone-on-start: true 3.2.4 启动类 ConfigServiceApplication.java package com.example.configservice;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;SpringBootApplication
EnableConfigServer
public class ConfigServiceApplication {public static void main(String[] args) {SpringApplication.run(ConfigServiceApplication.class, args);}
} 3.3 API网关Gateway Service
3.3.1 创建 gateway-service 模块
在父项目的 modules 目录下创建 gateway-service 模块。
3.3.2 gateway-service 的 pom.xml project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersionparentgroupIdcom.example/groupIdartifactIdbook-management-system/artifactIdversion1.0.0-SNAPSHOT/version/parentartifactIdgateway-service/artifactIddependenciesdependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-gateway/artifactId/dependencydependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-netflix-eureka-client/artifactId/dependency/dependencies
/project 3.3.3 gateway-service 的 application.yml server:port: 8080spring:application:name: gateway-servicecloud:gateway:routes:- id: book-serviceuri: lb://book-servicepredicates:- Path/books/**eureka:client:service-url:defaultZone: http://localhost:8761/eureka/ 3.3.4 启动类 GatewayServiceApplication.java package com.example.gatewayservice;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;SpringBootApplication
EnableDiscoveryClient
public class GatewayServiceApplication {public static void main(String[] args) {SpringApplication.run(GatewayServiceApplication.class, args);}
} 通过上述示例你可以看到Spring Boot和Spring Cloud的强大功能。Spring Boot简化了Spring应用的开发而Spring Cloud则提供了一整套微服务解决方案。
结合使用这两个框架可以快速构建健壮、可扩展的微服务应用。
图书管理系统实战
先简单分析这个实战的需求
创建一个基于Spring Boot和Spring Cloud的图书管理系统是一个很好的实践项目可以帮助你深入理解微服务架构的设计和实现。
下面是一个详细的步骤指南分析包括项目结构设计、技术栈选择、服务构建和集成等。
1. 技术栈选择
Spring Boot: 快速开发微服务的基础框架。Spring Cloud: 微服务治理工具集包含服务发现、配置管理、API网关等功能。数据库: 可以选择MySQL、PostgreSQL等关系型数据库。JPA/Hibernate: 持久层框架用于操作数据库。Eureka: 服务发现组件。Hystrix: 断路器用于处理分布式系统的延迟和容错。Zuul/Gateway: API网关用于路由请求。Config Server: 配置中心集中管理应用配置。RabbitMQ/Kafka: 消息队列用于异步通信。Swagger: API文档工具。Docker: 容器化部署。
2. 项目结构设计
2.1 微服务划分
图书服务 (Book Service): 处理与图书相关的业务逻辑。用户服务 (User Service): 管理用户信息和权限。订单服务 (Order Service): 处理借书和还书的订单。配置中心 (Config Service): 管理所有服务的配置文件。服务发现 (Discovery Service): 使用Eureka进行服务注册和发现。API网关 (Gateway Service): 使用Zuul或Spring Cloud Gateway作为入口点统一处理外部请求。
2.2 数据库设计
图书表: 包括图书ID、名称、作者、出版日期等字段。用户表: 包括用户ID、用户名、密码、邮箱等字段。订单表: 包括订单ID、用户ID、图书ID、借阅日期、归还日期等字段。
3. 创建Spring Boot项目
你可以使用Spring Initializr快速创建项目选择相应的依赖项
WebJPAMySQL Driver (或其他数据库驱动)Eureka Discovery Client (对于需要注册的服务)Hystrix (可选)Spring Cloud Config Client (对于需要读取配置的服务)
4. 实现各个服务
4.1 图书服务 (Book Service)
实体类: Book.java仓库接口: BookRepository.java 继承 JpaRepository服务类: BookService.java 提供业务逻辑控制器: BookController.java 处理HTTP请求
4.2 用户服务 (User Service)
实体类: User.java仓库接口: UserRepository.java服务类: UserService.java控制器: UserController.java
4.3 订单服务 (Order Service)
实体类: Order.java仓库接口: OrderRepository.java服务类: OrderService.java控制器: OrderController.java
5. 配置中心 (Config Service)
创建一个新的Spring Boot项目添加 spring-cloud-config-server 依赖。配置 application.yml 文件指定Git仓库地址和其他配置。启动类添加 EnableConfigServer 注解。
6. 服务发现 (Discovery Service)
创建一个新的Spring Boot项目添加 spring-cloud-starter-netflix-eureka-server 依赖。配置 application.yml 文件设置端口和注册中心地址。启动类添加 EnableEurekaServer 注解。
7. API网关 (Gateway Service)
创建一个新的Spring Boot项目添加 spring-cloud-starter-gateway 和 spring-cloud-starter-netflix-eureka-client 依赖。配置 application.yml 文件设置路由规则和服务发现地址。启动类无需额外注解。
8. 测试和部署
单元测试: 使用JUnit和Mockito编写单元测试。集成测试: 使用TestRestTemplate或RestAssured进行端到端测试。容器化: 使用Docker构建镜像编写Dockerfile和docker-compose.yml文件。部署: 将服务部署到Kubernetes集群或Docker Swarm集群。
9. 文档和监控
API文档: 使用Swagger生成API文档。监控: 使用Spring Boot Actuator和Prometheus/Grafana监控服务状态。
现在开始慢慢写出这个实战的代码
项目初始化服务发现Eureka图书服务Book Service配置中心Config ServiceAPI网关Gateway Service
1. 项目初始化
首先我们需要创建一个父项目来管理所有的子模块。使用Spring Initializr是一个不错的选择。
1.1 创建父项目
使用Spring Initializr创建一个父项目选择以下依赖
Spring WebSpring Data JPAMySQL DriverSpring Cloud Discovery (Eureka)Spring Cloud Config
1.2 父项目的 pom.xml project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersiongroupIdcom.example/groupIdartifactIdbook-management-system/artifactIdversion1.0.0-SNAPSHOT/versionpackagingpom/packagingmodulesmodulediscovery-service/modulemoduleconfig-service/modulemodulebook-service/modulemodulegateway-service/module/modulespropertiesjava.version11/java.versionspring-cloud.version2021.0.3/spring-cloud.version/propertiesdependencyManagementdependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-dependencies/artifactIdversion2.7.5/versiontypepom/typescopeimport/scope/dependencydependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-dependencies/artifactIdversion${spring-cloud.version}/versiontypepom/typescopeimport/scope/dependency/dependencies/dependencyManagement
/project 2. 服务发现Eureka
2.1 创建 discovery-service 模块
在父项目的 modules 目录下创建 discovery-service 模块。
2.2 discovery-service 的 pom.xml project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersionparentgroupIdcom.example/groupIdartifactIdbook-management-system/artifactIdversion1.0.0-SNAPSHOT/version/parentartifactIddiscovery-service/artifactIddependenciesdependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-netflix-eureka-server/artifactId/dependency/dependencies
/project 2.3 discovery-service 的 application.yml server:port: 8761eureka:instance:hostname: localhostclient:register-with-eureka: falsefetch-registry: falseservice-url:defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/ 2.4 discovery-service 的启动类 package com.example.discoveryservice;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;SpringBootApplication
EnableEurekaServer
public class DiscoveryServiceApplication {public static void main(String[] args) {SpringApplication.run(DiscoveryServiceApplication.class, args);}
} 3. 图书服务Book Service
3.1 创建 book-service 模块
在父项目的 modules 目录下创建 book-service 模块。
3.2 book-service 的 pom.xml project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersionparentgroupIdcom.example/groupIdartifactIdbook-management-system/artifactIdversion1.0.0-SNAPSHOT/version/parentartifactIdbook-service/artifactIddependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-data-jpa/artifactId/dependencydependencygroupIdmysql/groupIdartifactIdmysql-connector-java/artifactId/dependencydependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-netflix-eureka-client/artifactId/dependency/dependencies
/project 3.3 book-service 的 application.yml server:port: 8081spring:application:name: book-servicedatasource:url: jdbc:mysql://localhost:3306/book_db?useSSLfalseserverTimezoneUTCusername: rootpassword: rootjpa:hibernate:ddl-auto: updateshow-sql: trueeureka:client:service-url:defaultZone: http://localhost:8761/eureka/ 3.4 实体类 Book.java package com.example.bookservice.entity;import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;Entity
public class Book {IdGeneratedValue(strategy GenerationType.IDENTITY)private Long id;private String title;private String author;private String publicationDate;// Getters and Setters
} 3.5 仓库接口 BookRepository.java package com.example.bookservice.repository;import com.example.bookservice.entity.Book;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;Repository
public interface BookRepository extends JpaRepositoryBook, Long {
} 3.6 服务类 BookService.java package com.example.bookservice.service;import com.example.bookservice.entity.Book;
import com.example.bookservice.repository.BookRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;import java.util.List;
import java.util.Optional;Service
public class BookService {Autowiredprivate BookRepository bookRepository;public ListBook getAllBooks() {return bookRepository.findAll();}public OptionalBook getBookById(Long id) {return bookRepository.findById(id);}public Book saveBook(Book book) {return bookRepository.save(book);}public void deleteBook(Long id) {bookRepository.deleteById(id);}
} 3.7 控制器 BookController.java package com.example.bookservice.controller;import com.example.bookservice.entity.Book;
import com.example.bookservice.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;import java.util.List;
import java.util.Optional;RestController
RequestMapping(/books)
public class BookController {Autowiredprivate BookService bookService;GetMappingpublic ListBook getAllBooks() {return bookService.getAllBooks();}GetMapping(/{id})public OptionalBook getBookById(PathVariable Long id) {return bookService.getBookById(id);}PostMappingpublic Book saveBook(RequestBody Book book) {return bookService.saveBook(book);}DeleteMapping(/{id})public void deleteBook(PathVariable Long id) {bookService.deleteBook(id);}
} 3.8 启动类 BookServiceApplication.java package com.example.bookservice;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;SpringBootApplication
EnableDiscoveryClient
public class BookServiceApplication {public static void main(String[] args) {SpringApplication.run(BookServiceApplication.class, args);}
} 4. 配置中心Config Service
4.1 创建 config-service 模块
在父项目的 modules 目录下创建 config-service 模块。
4.2 config-service 的 pom.xml project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersionparentgroupIdcom.example/groupIdartifactIdbook-management-system/artifactIdversion1.0.0-SNAPSHOT/version/parentartifactIdconfig-service/artifactIddependenciesdependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-config-server/artifactId/dependency/dependencies
/project 4.3 config-service 的 application.yml server:port: 8888spring:application:name: config-servicecloud:config:server:git:uri: https://github.com/your-repo/config-repo.gitclone-on-start: true 4.4 启动类 ConfigServiceApplication.java package com.example.configservice;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;SpringBootApplication
EnableConfigServer
public class ConfigServiceApplication {public static void main(String[] args) {SpringApplication.run(ConfigServiceApplication.class, args);}
} 5. API网关Gateway Service
5.1 创建 gateway-service 模块
在父项目的 modules 目录下创建 gateway-service 模块。
5.2 gateway-service 的 pom.xml project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersionparentgroupIdcom.example/groupIdartifactIdbook-management-system/artifactIdversion1.0.0-SNAPSHOT/version/parentartifactIdgateway-service/artifactIddependenciesdependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-gateway/artifactId/dependencydependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-netflix-eureka-client/artifactId/dependency/dependencies
/project 5.3 gateway-service 的 application.yml server:port: 8080spring:application:name: gateway-servicecloud:gateway:routes:- id: book-serviceuri: lb://book-servicepredicates:- Path/books/**eureka:client:service-url:defaultZone: http://localhost:8761/eureka/ 5.4 启动类 GatewayServiceApplication.java package com.example.gatewayservice;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;SpringBootApplication
EnableDiscoveryClient
public class GatewayServiceApplication {public static void main(String[] args) {SpringApplication.run(GatewayServiceApplication.class, args);}
} 总结
以上是一个完整的基于Spring Boot和Spring Cloud的图书管理系统的基本构建过程。每个模块都有详细的代码和注释希望可以帮助到你。