完整搭建 SpringCloud 项目

news2024/9/24 5:23:43

目录

1、数据库表结构设计

2、项目结构设计搭建

   (1)创建父工程(SpringBoot 类型)

   (2)其他功能模块搭建

   (3)创建 eureka

   (4)创建common 模块

   (5)数据访问模块搭建


1、数据库表结构设计

2、项目结构设计搭建

 

   (1)创建父工程(SpringBoot 类型)

创建版本是JDK 1.8

填写项目信息

 

 在pom文件中添加

 

 代码如下:

 <packaging>pom</packaging>


        <swagger.version>2.9.2</swagger.version>
        <fastjson.version>1.2.51</fastjson.version>
 <dependencyManagement>
        <dependencies>
            <!-- springCloud -->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

 完整pom文件代码

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <packaging>pom</packaging>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.10</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.demo</groupId>
    <artifactId>qixing-parent</artifactId>
    <version>1.0</version>
    <name>qixing-parent</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>1.8</java.version>
        <swagger.version>2.9.2</swagger.version>
        <fastjson.version>1.2.51</fastjson.version>
    </properties>

    <dependencyManagement>
        <dependencies>
            <!-- springCloud -->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        
        <!--fastjson-->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>${fastjson.version}</version>
        </dependency>
        <!--swagger-->
        <!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>${swagger.version}</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>${swagger.version}</version>
        </dependency>


    </dependencies>

</project>

 在父工程中引入了SpringCloud等很多以后需要用到的依赖,以后创建的子工程就不需要自己引入了。

删除以上四个文件

 

   (2)其他功能模块搭建

 

创建 Maven 项目,注意版本号的选择

 

 添加这句话 

   <packaging>pom</packaging>

 

 删除 src 文件夹

 其他模块重复操作,创建qixing-service,qixing-service-api,qixing-web工程。注意pom文件需要修改打包方式

 

 

 (3)创建 eureka

 eureka的pom文件代码如下:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>qixing-parent</artifactId>
        <groupId>com.demo</groupId>
        <version>1.0</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>qixing-eureka</artifactId>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
    </dependencies>


</project>

 在eureka模块中的 resources中建立 application.yml

server:
  port: 8761
spring:
  application:
    name: qixing-eureka
eureka:
  instance:
    hostname: 127.0.0.1
  client:
    register-with-eureka: false   #是否将自己注册到eureka中
    fetch-registry: false         #是否从eureka中获取信息
    service-url:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka
  server:
    enable-self-preservation: false # 关闭自我保护
    eviction-interval-timer-in-ms: 5000 # 每隔5秒进行一次服务列表清理

在eureka中创建如下目录及文件

 代码如下:

package com.qixing;

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

/**
 * @Author caojun
 * @Date 2023/4/20 14:55
 * @Description :caojun java
 */
@SpringBootApplication
@EnableEurekaServer
public class EurekaApplication {
    public static void main(String[] args) {
        SpringApplication.run(EurekaApplication.class,args);
    }
}

启动可以看到 eureka 主页,访问 http://localhost:8761/

 

 (4)创建common 模块

 在common模块中的pom文件代码如下:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>qixing-parent</artifactId>
        <groupId>com.demo</groupId>
        <version>1.0</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>qixing-common</artifactId>
    <dependencies>
        <!--web起步依赖-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!-- redis 使用-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>
        <!--eureka-client-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
            <version>3.1.3</version>
        </dependency>
        <!--openfeign-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
            <version>3.0.2</version>
        </dependency>

        <!--json字符串转换-->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.15</version>
        </dependency>
        <!--发送短信等需要的依赖-->
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.2.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpcore</artifactId>
            <version>4.2.1</version>
        </dependency>
        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.6</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-util</artifactId>
            <version>9.3.7.v20160115</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.5</version>
            <scope>test</scope>
        </dependency>
    </dependencies>


</project>

(5)数据访问模块搭建

 

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>qixing-parent</artifactId>
        <groupId>com.demo</groupId>
        <version>1.0</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>qixing-common-db</artifactId>
    <dependencies>
        <dependency>
            <groupId>com.demo</groupId>
            <artifactId>qixing-common</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.23</version>
        </dependency>
        <!-- 连接池 -->
        <!-- <dependency>
           <groupId>com.alibaba</groupId>
           <artifactId>druid</artifactId>
           <version>1.1.14</version>
       </dependency> -->
        <!--druid 依赖-->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid-spring-boot-starter</artifactId>
            <version>1.1.9</version>
        </dependency>
        <!-- MyBatisPlus -->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.4.2</version>
        </dependency>

    </dependencies>


</project>

 

接下来就是在service-api模块搭建实际的业务代码了,略

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/452536.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

jmeter常用组件1

常用的组件 常用的组件1&#xff0c;配置元件 1.HTTP请求默认值2.HTTP信息头管理器3.HTTP Cookie管理器4.用户自定义变量5.csv数据导入 2&#xff0c;集合点3&#xff0c;后置处理器 1.debug处理器2.json提取器 本文永久更新地址: 1&#xff0c;配置元件 1.HTTP请求默认值 在…

ASP.NET Core MVC 从入门到精通之Razor语法

随着技术的发展&#xff0c;ASP.NET Core MVC也推出了好长时间&#xff0c;经过不断的版本更新迭代&#xff0c;已经越来越完善&#xff0c;本系列文章主要讲解ASP.NET Core MVC开发B/S系统过程中所涉及到的相关内容&#xff0c;适用于初学者&#xff0c;在校毕业生&#xff0c…

PyQt在界面/子界面中添加横线

问题&#xff1a; 自己写个了处理数据的小程序&#xff0c;想要在不同的部分之间做个区域划分&#xff0c;使用实线或者虚线标记。 找了几个界面方法&#xff1a;1.使用画图QPainter,画所需要的线。 2.添加按钮&#xff0c;将按钮设置成线的形式 这两种方式都不适合我这个界…

着色器语言 GLSL (opengl-shader-language)入门大全

GLSL 中文手册 基本类型: 类型说明void空类型,即不返回任何值bool布尔类型 true,falseint带符号的整数 signed integerfloat带符号的浮点数 floating scalarvec2, vec3, vec4n维浮点数向量 n-component floating point vectorbvec2, bvec3, bvec4n维布尔向量 Boolean vectori…

广告投放ROI如何计算?实现广告效果最大化

大家好&#xff01;我是东哥&#xff0c;一个专注于跨境电商的小商家。今天&#xff0c;我要和大家分享一下广告投放中的一个关键指标——ROI&#xff0c;也就是投资回报率。这个指标非常重要&#xff0c;因为它可以帮助我们评估广告的效果&#xff0c;让我们知道我们的广告投放…

SpringCloud消息驱动——Stream

Stream 本专栏学习内容来自尚硅谷周阳老师的视频 有兴趣的小伙伴可以点击视频地址观看 SpringCloud Stream是SpringCloud的消息驱动&#xff0c;之前的微服务学的好好的&#xff0c;为什么会突然冒出一个这么个东西来增加我们的学习量呢&#xff1f; 一听到消息&#xff0c;那…

u盘文件不见但还占用容量文件办法?

将U盘插入电脑的时候为什么会出现“U盘文件突然不见但还占用空间”的提示框呢?遇到这个问题时又该怎么处理呢?别慌&#xff0c;下面小编就来给大家演示一下子解决U盘文件突然不见但还占用空间这个问题的解决方法。 u盘文件不见但还占用容量文件办法&#xff1f; u盘文件不见但…

短视频平台-小说推文(最右)推广任务详情

最右推荐书单 https://nr6mwfrzw8.feishu.cn/sheets/shtcnVgsBY18qft FqBG9b8eYFnc?sheetpfiUaC 复制链接到飞书或浏览器打开 最右会员 1.1关键词 最右关键词审核时间周一~周日 上午:10点前提交&#xff0c;15:00点前可查下午:15点前提交&#xff0c;20:00点前可查注意: …

盘点几款还不错的企业网盘产品

企业网盘的出现&#xff0c;为企业提供文件安全管理&#xff0c;团队协作服务&#xff0c;解决了便捷性与安全性等问题&#xff0c;受到了企业的青睐。市面上的企业网盘工具也是五花八门&#xff0c;我们该如何选择适合自己团队的网盘工具呢&#xff1f; 本文盘点了几款还不错的…

2023年软件测试的前景?测试工程师技能提升,进阶自动化测试...

目录&#xff1a;导读 前言一、Python编程入门到精通二、接口自动化项目实战三、Web自动化项目实战四、App自动化项目实战五、一线大厂简历六、测试开发DevOps体系七、常用自动化测试工具八、JMeter性能测试九、总结&#xff08;尾部小惊喜&#xff09; 前言 2023年软件测试行…

中国社科院与美国杜兰大学金融管理硕士项目——努力撑起未来的一片天

牛顿说&#xff1a;如果说我看得比别人更远些&#xff0c;那是因为我站在巨人的肩膀上。人类文明浩如烟海&#xff0c;我们每个人都是吸收着前人的精神食粮长大。父母也是尽全力地给我们提供好的学习环境&#xff0c;让我们站在他们的肩头上&#xff0c;青出于蓝而胜于蓝。如今…

新互联网人必学-产品经理课无密为伊消得人憔悴

新互联网人必学-产品经理课 download&#xff1a;https://www.666xit.com/3832/ 产品经理&#xff1a;连接用户需求和产品设计的重要角色 随着移动互联网的迅猛发展&#xff0c;产品经理已成为越来越多IT公司中不可或缺的职位。作为一名产品经理&#xff0c;他所扮演的角色是…

你掌握了stream流的全部新特性吗?

我们知道很早之前java8对于之前的版本更新了许多 新的支持&#xff0c;比如lamda函数式接口的支持&#xff0c;支持更多函数式接口的使用&#xff0c;对链表&#xff0c;数组&#xff0c;队列&#xff0c;集合等实现了Collectio接口的数据结构提供了StreamSupport.stream()支持…

Windows下版本控制器(SVN)-验证是否安装成功+配置版本库+启动服务器端程序

文章目录 基础知识-Windows下版本控制器(SVN)3、Subversion 安装与配置3.1 验证是否安装成功。3.2 配置版本库3.3 启动服务器端程序 基础知识-Windows下版本控制器(SVN) 3、Subversion 安装与配置 TortoiseSVN安装与配置网上资料太多了&#xff0c;这里就不阐述了。 3.1 验证是…

LinkedHashMap如何实现LRU缓存淘汰策略?

本文目录 1.LRU是什么&#xff1f;2.如何使用LinkedHashMap实现LRU?3.LinkedHashMap源码分析3.1 LinkedHashMap简介3.2 继承体系3.3 内部数据存储结构3.4源码解析属性&#xff1a;构造方法&#xff1a;afterNodeInsertion(boolean evict)方法afterNodeAccess(Node e)方法after…

一种应用于车载系统的GPS接收机射频前端的设计

一种应用于车载系统的GPS接收机射频前端的设计 GPS&#xff08;GLOBLE POSITIONING SYSTEM&#xff09;是一种可以定时和测距的空间交会定点导航系统&#xff0c;它可以向全球用户提供连续、实时、高精度的三维位置、三维速度和实践信息。GPS提供两种服务&#xff1a;标准定位…

科研小技巧 | 用ArcGIS绘制研究区地图

目录 01 地图的导入 02 设置十段线小图框 03 设置研究区示意图 04 添加细节04添加细节 05 添加省份名称 06 对研究区额外上色 论文用图对准确性和美观度有一定要求&#xff0c;而ArcGIS具有强大的地图制作功能&#xff0c;可以利用该软件快速制作研究区地图。 01 地图的导…

实力认证 | 睿士主机取证溯源系统再获国产化兼容性认证

睿士主机取证溯源系统喜获鲲鹏技术认证 近日&#xff0c;中睿天下自主研发的睿士主机取证溯源系统与华为技术有限公司旗下鲲鹏&#xff08;Kunpeng&#xff09;920处理器完成兼容性测试认证&#xff0c;并获得鲲鹏技术认证书。这表明睿士主机取证溯源系统可为鲲鹏920处理器主机…

操作系统原理 —— 进程有哪几种状态?状态之间如何切换?(七)

进程的五种状态 首先我们一起来看一下进程在哪些情况下&#xff0c;会有不同的状态表示。 创建态、就绪态 当我们刚开始运行程序的时候&#xff0c;操作系统把可执行文件加载到内存的时候&#xff0c;进程正在被创建的时候&#xff0c;它的状态是创建态&#xff0c;在这个阶…

【两个月算法速成】day02

目录 977. 有序数组的平方 题目链接 思路&#xff1a; 代码 &#xff1a; 209. 长度最小的子数组 题目链接 思路 代码 59. 螺旋矩阵 II 题目链接 思路 代码 总结 977. 有序数组的平方 题目链接 ​​​​​​力扣 思路&#xff1a; 双指针法 因为数组是非递减的…