• 快速搭建一个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);
    }

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

     

  • 相关阅读:
    storm学习之七-storm UI页面参数详解
    kafka学习之-KafkaOffsetMonitor后台监控
    hbase深入了解
    storm学习之六-使用Maven 生成jar包多种方式
    kafka学习之-集群配置及安装
    Python的Web应用框架--Django
    plugins/python/uwsgi_python.h:2:20: fatal error: Python.h: No such file or directory
    key-value数据库-Redis
    SUSE 12安装详解
    分布式网络文件系统--MooseFS
  • 原文地址:https://www.cnblogs.com/wanqiang/p/15835631.html
Copyright © 2020-2023  润新知