黄色网址大全免费-黄色网址你懂得-黄色网址你懂的-黄色网址有那些-免费超爽视频-免费大片黄国产在线观看

專注Java教育14年 全國咨詢/投訴熱線:400-8080-105
動(dòng)力節(jié)點(diǎn)LOGO圖
始于2009,口口相傳的Java黃埔軍校
首頁 hot資訊 手把手教你SpringCloud項(xiàng)目搭建

手把手教你SpringCloud項(xiàng)目搭建

更新時(shí)間:2021-12-28 11:55:05 來源:動(dòng)力節(jié)點(diǎn) 瀏覽2703次

手把手教你搭建spring cloud項(xiàng)目

IDE開發(fā)工具:IntelliJ IDEA 14.0.2

版本管理:Maven

技術(shù)棧:spring cloud

環(huán)境:JDK 1.8

1.創(chuàng)建Maven項(xiàng)目

(1)文件->新建項(xiàng)目->maven,如圖:

文件->新建項(xiàng)目

(2)填寫模塊名稱和項(xiàng)目路徑

按照以下步驟創(chuàng)建 Maven 項(xiàng)目。

這時(shí)候的項(xiàng)目不是spring boot項(xiàng)目!!

2.將maven項(xiàng)目轉(zhuǎn)為spring boot項(xiàng)目

(1)pom.xml 引入所需的jar包

注:根據(jù)各項(xiàng)目實(shí)際情況,建筑業(yè)主為maven私人倉庫

介紹SpringBoot所需的jar包

引入spring cloud需要的jar包

引入ereka服務(wù)注冊發(fā)現(xiàn)客戶端需要的jar包

介紹mybatis spring cloud 依賴的jar包

介紹kafka需要的jar包

引入redis需要的jar包

配置中心Spring config client的引入依賴jar包等,根據(jù)各個(gè)項(xiàng)目的需要。

<?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.**inks.e**s</groupId>
    <artifactId>msg</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging> 
    <name>msg</name>
    <description>Demo project for Spring Boot</description> 
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.6.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent> 
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <tomcat.version>8.5.30</tomcat.version>
    </properties> 
    <dependencies>
        <!--spring-cloud-config introduce -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>
        <!--spring-cloud Monitoring function is introduced, which can be used to refresh configuration files dynamically -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka</artifactId>
        </dependency>
        <!-- introduce feign rely on -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-feign</artifactId>
        </dependency>
        <!-- kafka rely on -->
        <dependency>
            <groupId>org.springframework.kafka</groupId>
            <artifactId>spring-kafka</artifactId>
        </dependency>
        <!-- redis rely on -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>
        <!-- Spring Boot -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency> 
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <!--mybatis to configure-->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>1.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis.generator</groupId>
            <artifactId>mybatis-generator-core</artifactId>
            <version>1.3.2</version>
        </dependency>
        <dependency>
            <groupId>com.epaylinks.efps</groupId>
            <artifactId>common</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>com.epaylinks.efps</groupId>
            <artifactId>logtracer</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency> 
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-math</artifactId>
            <version>2.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5.3</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpasyncclient</artifactId>
            <version>4.1.1</version>
        </dependency>
        <dependency>
            <groupId>io.github.openfeign.form</groupId>
            <artifactId>feign-form-spring</artifactId>
            <version>3.2.2</version>
        </dependency>
        <dependency>
            <groupId>io.github.openfeign.form</groupId>
            <artifactId>feign-form</artifactId>
            <version>3.2.2</version>
        </dependency>
    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Dalston.SR2</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>
            <plugin>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>1.3.2</version>
                <configuration>
                    <configurationFile>src/main/resources/generatorConfig-mch.xml</configurationFile>
                    <verbose>true</verbose>
                    <overwrite>true</overwrite>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>com.oracle</groupId>
                        <artifactId>ojdbc6</artifactId>
                        <version>11.1.0.7.0</version>
                    </dependency>
                    <dependency>
                        <groupId>org.mybatis.generator</groupId>
                        <artifactId>mybatis-generator-core</artifactId>
                        <version>1.3.2</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>
</project>

(2)創(chuàng)建spring cloud項(xiàng)目的主入口類** Application

package com.**s.**s;
import com.**ks.e**.common.util.SpringContextUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.kafka.annotation.EnableKafka;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.client.RestTemplate; 
@RefreshScope
@EnableEurekaClient
@EnableFeignClients
@EnableKafka
@EnableScheduling
@EnableAspectJAutoProxy(proxyTargetClass=true , exposeProxy=true)
@SpringBootApplication
public class MsgApplication {
    // Note that since we inject RestTemplate into the controller, we need to instantiate an instance of this class at startup
    @Autowired
    private RestTemplateBuilder builder; 
        // Use RestTemplateBuilder to instantiate the RestTemplate object. spring has injected the RestTemplateBuilder instance by default
    @Bean
    public RestTemplate restTemplate() {
        return builder.build();
    } 
    public static void main(String[] args) {
        SpringApplication springApplication = new SpringApplication(MsgApplication.class);
        SpringContextUtils.setApplicationContext(springApplication.run(args));
    }
}

@SpringBootApplication的注解說明這個(gè)項(xiàng)目是一個(gè)SpringBoot項(xiàng)目,這個(gè)類是項(xiàng)目的主入口類。

使用以下主要方法啟動(dòng)應(yīng)用程序

    public static void main(String[] args) {
        SpringApplication springApplication = new SpringApplication(MsgApplication.class);
        SpringContextUtils.setApplicationContext(springApplication.run(args));
    }

至此,spring boot項(xiàng)目已經(jīng)完成了大半。接下來是配置數(shù)據(jù)庫連接和registry config、ereka等配置文件

3.Registry和服務(wù)發(fā)現(xiàn)配置

(1)讀取Spring Config Center配置項(xiàng)目的配置文件

樓主使用Spring Config Center作為配置中心,配置讀取項(xiàng)目所需的各種連接和配置信息(Spring Config Center這里不再詳細(xì)介紹)

(2)GitLab遠(yuǎn)程托管配置信息

Spring Config Center配置項(xiàng)目的連接和讀取權(quán)限后,在gitlab上配置項(xiàng)目的各種需要的信息

在此處查看另一篇文章

spring cloud項(xiàng)目使用gitLab作為配置中心

(3)加載項(xiàng)目中各個(gè)環(huán)境對應(yīng)的配置文件信息(dev、test、prod、uat)

以dev開發(fā)環(huán)境為例

按圖標(biāo)順序加載

所有spring cloud項(xiàng)目都是從bootstrap.yml文件開始加載項(xiàng)目所需的各種連接和配置信息。這是spring cloud core自帶的決定??梢匝芯吭创a,這里不詳述。

4.bootstrap-dev.yml的配置如下:

spring:
  application:
    name: msg
  cloud:
    config:
      uri: http://172.20 *. 4 *. 80:9000 / ? configure the url of the spring cloud config server
      profile: dev                      # Specify profile
      label: master                     # Specify the branch of the gitlab repository

主要是連接spring cloud config server獲取遠(yuǎn)程gitlab上的配置信息。

5.application-dev.yml的配置如下:

eureka:
  client:
    registerWithEureka: true
    service-url:
      defaultZone: http://172.20.4.80:8000/eureka/
swagger:
  enable: true

主要用于連接eureka服務(wù)注冊和發(fā)現(xiàn)

至此,春關(guān)工程已基本完成。下一步就是為各種數(shù)據(jù)庫建表,配置Mybatis,更新代碼。

提交申請后,顧問老師會(huì)電話與您溝通安排學(xué)習(xí)

免費(fèi)課程推薦 >>
技術(shù)文檔推薦 >>
主站蜘蛛池模板: 人人欧美 | 国产精品麻豆高清在线观看 | 亚洲性片| 免费一级毛片清高播放 | 欧美日韩片 | 国产成人麻豆精品video | 国产视频福利一区 | 日韩不卡中文字幕 | 欧美18-19| 在线www 天堂网在线 | 欧美一级性 | 国产 日韩 欧美 综合 | 激情插| 免费成年网 | 九九精品99 | 日韩欧美一区二区三区不卡视频 | 手机在线免费毛片 | 国产成人精品午夜二三区 | 久久天天干 | 视频一区二区三区在线观看 | 美女国内精品自产拍在线播放 | 小明明看看视频永久免费网 | 天天干夜夜爽天天操夜夜爽视频 | 真实国产乱弄免费视频 | 五月婷婷色 | aa看片 | 免费黄色欧美视频 | 97精品久久天干天天蜜 | 玖玖在线播放 | 国产精品1234区 | 男女性免费视频观看 | 亚洲无线乱码高清在线观看一区 | 你懂的视频在线播放 | 国产凹凸一区在线观看视频 | 秋霞午夜伦理片 | 91日本| 青草热久精品视频在线观看 | 国产又黄又湿又刺激不卡网站 | 欧美理论在线 | 国产午夜亚洲精品不卡 | 亚洲天堂网站在线 |