spring cloud(一)项目搭建

15 篇文章 0 订阅

简介

本文只介绍spring cloud项目的搭建,后面文章会依次介绍其他微服务的加入。
关于spring cloud的介绍不在重复,可以参考这个总结 https://zhuanlan.zhihu.com/p/95696180?from_voters_page=true
本文使用的版本 spring cloud: Greenwich.SR3, spring boot:2.1.7.RELEASE

idea项目搭建

1.idea file-new 创建maven工程
2.为工程添加mvn镜像配置,我使用的阿里云mvn仓库,复制以下内容到本地的xxx.xml中,file-settings 找到maven,设置User setting file为xxx.xml

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
 
  <localRepository>C:\\Users\\用户名\\.m2\\repository</localRepository>
  <interactiveMode>true</interactiveMode>
  <offline>false</offline>
  <pluginGroups>
 
  </pluginGroups>
 
  <proxies>
 
  </proxies>
 
  <servers>
 
  </servers>
 
  <mirrors>
 
    <mirror>
      <id>alimaven</id>
      <name>aliyun maven</name>
      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
      <mirrorOf>central</mirrorOf>
    </mirror>
  
  </mirrors>
 
  <profiles>
 
  </profiles>
  <activeProfiles>
  </activeProfiles>
</settings>

3.pom文件中设置自身参数,并添加pom

<groupId>com.zjk.test</groupId>
    <artifactId>test</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>

4.添加spring boot的parent依赖

<!-- ================================================= -->
    <!-- Spring boot -->
    <!-- ================================================= -->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.7.RELEASE</version>
        <relativePath/>
    </parent>

5.添加spring cloud 依赖

<dependencyManagement>
        <dependencies>
            <!-- ================================================= -->
            <!-- Spring Cloud -->
            <!-- ================================================= -->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Greenwich.SR3</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.data</groupId>
                <artifactId>spring-data-commons</artifactId>
                <version>1.13.11.RELEASE</version>
            </dependency>
     </dependencies>
    </dependencyManagement>

注意 spring cloud版本要与spring boot对应起来
可以参考
在这里插入图片描述
6.右击工程点击maven->reload project 可以下载依赖
依赖下载可能会出现一部分包不在External Libraries中,点击maven的包保存地址(setting-maven-Local repository的目录)发现依赖的jar都在了,这时可以重启下idea,我的就是这样都出现了

7.为项目设置SDK file-Project Structure,如果使用本文相同的版本需要设置SDK为Java1.8,最新的SDK15不支持这些版本,后续的启动会报错。

8.至此已配置完毕,删除project下的src目录,等待后面添加具体的微服务

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值