欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

spring cloud 工程创建

程序员文章站 2022-06-13 11:36:40
...

spring cloud 工程创建

https://spring.io/projects/spring-cloud#overview
springcloud   springboot
Hoxton(H版)     2.2.X  (推荐)
Greenwich(G版)  2.1.X
Finchley        2.0.x
版本推荐:
Java8   maven3.5+  mysql 5.7
boot2.2.2   cloud H版SR1,  cloud alibaba 2.1.0
创建工程
新建mvn工程 SDk选择java1.8,勾选 create from archetype(mvn 框架), 选择地下的maven-archetype-site
GroupId 包名   例如:com.lizhao.aaa
artifactid 工程名  例如:cloudlearn
mvn home 文件夹选择, 选择自己安装的
project Name 项目名 cloudlearn
	enable auto import(开启maven自动导入功能)
字符编码改成 utf-8:settings ->editor-> file encoding(encodeing utf-8  有三个
												transprent native-to-ascii conversion Y)
注解生效: settings-> build-> compiler ->annatation processors(enable annatation processors)
java编译器选择 setting->build-> compiler -> java compiler
参考 pom.xml
<?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.lizhao.learn</groupId>
  <artifactId>cloudlz</artifactId>
  <version>1.0-SNAPSHOT</version>
  <!-- 表示是 pom 总的父工程 -->
  <packaging>pom</packaging>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <junit.version>4.12</junit.version>
    <log4j.version>1.2.17</log4j.version>
    <lombok.version>1.16.18</lombok.version>
    <mysql.version>5.1.47</mysql.version>
    <druid.version>1.1.16</druid.version>
    <mybatis.spring.boot.version>1.3.0</mybatis.spring.boot.version>
  </properties>
  <!-- 子模块继承之后 锁定版本  子module 不用写groupID 和version-->
  <!--dependencyManagement 总的依赖管理 一般在父pom中使用 ,升级版本只需要修改 父 pom -->
  <!--dependencyManagement 不实际进行引入jar包,只做声明,因此子项目需要显示的声明需要用的依赖,依赖的版本号默认去父工程找
                                                不会自动获取父工程dependencyManagement中定义的依赖-->
  <dependencyManagement>
    <dependencies>
      <!-- spring boot 版本 2.2.2 -->
      <!--springboot 2.2.2-->
      <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-dependencies</artifactId>
        <version>2.2.2.RELEASE</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
      <!-- spring cloud 版本 H.SR1 -->
      <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-dependencies</artifactId>
        <version>Hoxton.SR1</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>

      <!-- spring cloud alibaba  -->
      <dependency>
        <groupId>com.alibaba.cloud</groupId>
        <artifactId>spring-cloud-alibaba-dependencies</artifactId>
        <version>2.1.0.RELEASE</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
      <!-- mysql  -->
      <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>${mysql.version}</version>
      </dependency>

      <!-- druid  -->
      <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>druid</artifactId>
        <version>${druid.version}</version>
      </dependency>
      <!-- druid  -->
      <dependency>
        <groupId>org.mybatis.spring.boot</groupId>
        <artifactId>mybatis-spring-boot-starter</artifactId>
        <version>${mybatis.spring.boot.version}</version>
      </dependency>
    </dependencies>

  </dependencyManagement>

</project>

建module

父工程名(右键)-> new -> module(mvn sdk1.8) -> 编辑子module名字
spring cloud 工程创建

修改子module的pom, 增加dependencies

创建yml

子module  src.main.resource(文件夹右键,新建文件application.yml)
server:
  port: 8001
spring:
  application:
    name: cloud-payment-service
  datasource:
    # 当前数据源操作类型
    type: com.alibaba.druid.pool.DruidDataSource
    # mysql驱动类
    #driver-class-name: com.mysql.cj.jdbc.Driver
    driver-class-name: org.gjt.mm.mysql.Driver
    url: jdbc:mysql://localhost:3306/db2019?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=GMT%2B8
    username: root
    password: root
mybatis:
  mapper-locations: classpath*:mapper/*.xml
  type-aliases-package: com.lizhao.cloud01.entities

创建入口类 @SpringBootApplication

package com.lizhao.cloud01;


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

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

参考https://github.com/leelovejava/cloud2020

相关标签: springcloud