spring cloud alibaba(四)搭建项目基础框架

折腾这么久,终于开始搭建项目基础框架了。

1.新建项目

选择maven项目
在这里插入图片描述
在这里插入图片描述

2.删除无用包

在这里插入图片描述

3.修改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">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.hansiwei</groupId>
    <artifactId>springCloudAlibabaLearn</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <java.version>1.8</java.version>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
        <maven.compiler.version>3.8.6</maven.compiler.version>
    </properties>


    <!--pom版本控制,通过dependencyManagement完成继承-->
    <dependencyManagement>
        <dependencies>
            <!-- springboot -->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-parent</artifactId>
                <version>2.7.3</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <!-- springCloud -->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>2021.0.3</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <!-- alibaba -->
            <dependency>
                <groupId>com.alibaba.cloud</groupId>
                <artifactId>spring-cloud-alibaba-dependencies</artifactId>
                <version>2021.0.1.0</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

4.至此基础搭建完成

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Spring Cloud Alibaba是阿里巴巴推出的一套基于Spring Cloud的微服务框架。它包含了多个组件,如服务注册中心、配置中心、分布式事务等,可以帮助开发者快速搭建分布式应用。 下面是Spring Cloud Alibaba项目搭建的步骤和注意事项: 步骤: 1. 创建Spring Boot项目:可以使用Spring Initializr或者自己手动创建。 2. 添加依赖:在pom.xml文件中添加Spring Cloud Alibaba的依赖,如: ```xml <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> <version>2.2.1.RELEASE</version> </dependency> ``` 其中,spring-cloud-starter-alibaba-nacos-discovery是服务注册中心的依赖。 3. 配置文件:在application.properties或application.yml中配置服务注册中心的地址和端口,如: ```properties spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848 ``` 4. 编写代码:编写服务提供者和消费者的代码,可以使用Feign或者RestTemplate来调用服务。 5. 启动应用:运行Spring Boot应用,访问http://localhost:8080可以看到服务已经注册到了Nacos中心。 注意事项: 1. 版本兼容性:Spring Cloud Alibaba中的各个组件有版本兼容性的要求,需要根据自己的需求选择合适的版本。 2. 服务注册中心的选择:Spring Cloud Alibaba中提供了多种服务注册中心的选择,如Nacos、Consul、Zookeeper等,需要根据自己的需求选择合适的注册中心。 3. 分布式事务的使用:Spring Cloud Alibaba中提供了分布式事务的解决方案,如Seata等,需要根据自己的需求进行选择和配置。 4. 配置中心的使用:Spring Cloud Alibaba中提供了配置中心的解决方案,如Nacos Config等,可以将配置文件集中管理,方便应用的部署和维护。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值