• 快速搭建一个spring cloud 子模板好记性不如烂笔头


     

     

     

     

     建 application.yml 文件

    server:
    # 服务端口号
    port: 7609
    spring:
    application:
    # 服务名称 - 服务之间使用名称进行通讯
    name: service-test4
    datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/mysql?useUnicode=true&characterEncoding=UTF-8&&serverTimezone=GMT
    username: root
    password: 123456

    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>
    <groupId>com.example</groupId>
    <artifactId>service-test4</artifactId>
    <version>1.0</version>
    <name>测试服务7</name>
    <description>service-test4</description>
    <parent>
    <groupId>com.example</groupId>
    <artifactId>spring-cloud-demo</artifactId>
    <version>1.0</version>
    </parent>
    <properties>
    <java.version>1.8</java.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <spring-boot.version>2.3.7.RELEASE</spring-boot.version>
    <spring-cloud.version>Greenwich.RELEASE</spring-cloud.version>
    </properties>

    <dependencyManagement>
    <dependencies>
    <dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-dependencies</artifactId>
    <!-- SpringBoot 2.1.X 以上版本这样配置 -->
    <version>${spring-cloud.version}</version>
    <!-- <version>Dalston.RC1</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>
    <dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    </dependency>
    </dependencies>

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

    <build>
    <plugins>
    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.1</version>
    <configuration>
    <source>1.8</source>
    <target>1.8</target>
    <encoding>UTF-8</encoding>
    </configuration>
    </plugin>
    <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <version>2.3.7.RELEASE</version>
    <configuration>
    <mainClass>com.example.servicetest4.ServiceTest4Application</mainClass>
    </configuration>
    <executions>
    <execution>
    <id>repackage</id>
    <goals>
    <goal>repackage</goal>
    </goals>
    </execution>
    </executions>
    </plugin>
    </plugins>
    </build>

    </project>
    启动类:
    package com.example.servicetest4;

    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
    import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
    //(exclude= {DataSourceAutoConfiguration.class}) 加上这注解不用配置数据源,不加需要配置数据源

    @SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})
    @EnableEurekaClient
    public class ServiceTest4Application {

    public static void main(String[] args) {
    SpringApplication.run(ServiceTest4Application.class, args);
    }

    }
    测试看到下面两个图:说明简单的一个子项目以及搭建成功

     

  • 相关阅读:
    数据科学面试应关注的6个要点
    Python3.9的7个特性
    一种超参数优化技术-Hyperopt
    梯度下降算法在机器学习中的工作原理
    MQ(消息队列)功能介绍
    D. The Number of Pairs 数学
    F. Triangular Paths 思维
    D. XOR-gun 思维和 + 前缀
    C. Basic Diplomacy 思维
    D. Playlist 思维
  • 原文地址:https://www.cnblogs.com/wanqiang/p/15835631.html
Copyright © 2020-2023  润新知