spring cloud+spring boot搭建父工程子工程,主要是pom文件参考
1.首先创建父工程,修改pom.xml,内容如下:
1 <?xml version="1.0" encoding="UTF-8"?> 2 <project xmlns="http://maven.apache.org/POM/4.0.0" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 5 <modelVersion>4.0.0</modelVersion> 6 <groupId>com.atguigu.springcloud</groupId> 7 <artifactId>microservicecloud</artifactId> 8 <packaging>pom</packaging> 9 <version>1.0-SNAPSHOT</version> 10 <!--子模块--> 11 <modules> 12 <!--刚开始创建可省略--> 13 <module>microservicecloud-api</module> 14 <module>microservicecloud-provider-dapt-8001</module> 15 <module>microservicecloud-consumer-dept-80</module> 16 <module>microservicecloud-eureka-7001</module> 17 <module>microservicecloud-eureka-7002</module> 18 <module>microservicecloud-eureka-7003</module> 19 <module>microservicecloud-provider-dapt-8002</module> 20 <module>microservicecloud-provider-dapt-8003</module> 21 <module>microservicecloud-consumer-dept-feign</module> 22 <module>microservicecloud-provider-dept-hystrix-8001</module> 23 <module>microservicecloud-consumer-hystrx-dashboard</module> 24 <module>microservicecloud-zuul-geteway-9527</module> 25 <module>microservicecloud-config-3344</module> 26 </modules> 27 28 <properties> 29 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 30 <maven.compiler.source>1.8</maven.compiler.source> 31 <maven.compiler.target>1.8</maven.compiler.target> 32 <junit.version>4.12</junit.version> 33 <log4j.version>1.2.17</log4j.version> 34 <lombok.version>1.16.18</lombok.version> 35 </properties> 36 <dependencyManagement> 37 <dependencies> 38 39 <!--spring cloud--> 40 <dependency> 41 <groupId>org.springframework.cloud</groupId> 42 <artifactId>spring-cloud-dependencies</artifactId> 43 <version>Dalston.SR1</version> 44 <type>pom</type> 45 <scope>import</scope> 46 </dependency> 47 48 <!--spring boot--> 49 <dependency> 50 <groupId>org.springframework.boot</groupId> 51 <artifactId>spring-boot-dependencies</artifactId> 52 <version>1.5.9.RELEASE</version> 53 <type>pom</type> 54 <scope>import</scope> 55 </dependency> 56 57 <!--mysql驱动--> 58 <dependency> 59 <groupId>mysql</groupId> 60 <artifactId>mysql-connector-java</artifactId> 61 <version>5.0.4</version> 62 </dependency> 63 64 <!--德鲁伊--> 65 <dependency> 66 <groupId>com.alibaba</groupId> 67 <artifactId>druid</artifactId> 68 <version>1.0.31</version> 69 </dependency> 70 71 <!--spring boot和mybatis整合--> 72 <dependency> 73 <groupId>org.mybatis.spring.boot</groupId> 74 <artifactId>mybatis-spring-boot-starter</artifactId> 75 <version>1.3.0</version> 76 </dependency> 77 78 <!--logback日志--> 79 <dependency> 80 <groupId>ch.qos.logback</groupId> 81 <artifactId>logback-core</artifactId> 82 <version>1.2.3</version> 83 </dependency> 84 85 <!--测试--> 86 <dependency> 87 <groupId>junit</groupId> 88 <artifactId>junit</artifactId> 89 <version>${junit.version}</version> 90 <scope>test</scope> 91 </dependency> 92 93 <!--log4日志--> 94 <dependency> 95 <groupId>log4j</groupId> 96 <artifactId>log4j</artifactId> 97 <version>${log4j.version}</version> 98 </dependency> 99 100 </dependencies> 101 </dependencyManagement> 102 103 <build> 104 <finalName>microservicecloud</finalName> 105 <resources> 106 <resource> 107 <directory>src/main/resources</directory> 108 <filtering>true</filtering> 109 </resource> 110 </resources> 111 <plugins> 112 <plugin> 113 <groupId>org.apache.maven.plugins</groupId> 114 <artifactId>maven-resources-plugin</artifactId> 115 <configuration> 116 <delimiters> 117 <delimit>$</delimit> 118 </delimiters> 119 </configuration> 120 </plugin> 121 </plugins> 122 </build> 123 124 </project>
2.创建子模块api,修改pom.xml
1 <?xml version="1.0" encoding="UTF-8"?> 2 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 3 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4 <modelVersion>4.0.0</modelVersion> 5 6 <parent><!-- 子类里面显示声明才能有明确的继承表现,无意外就是父类的默认版本否则自己定义 --> 7 <groupId>com.atguigu.springcloud</groupId> 8 <artifactId>microservicecloud</artifactId> 9 <version>1.0-SNAPSHOT</version> 10 </parent> 11 12 <artifactId>microservicecloud-api</artifactId><!-- 当前Module我自己叫什么名字 --> 13 14 <dependencies><!-- 当前Module需要用到的jar包,按自己需求添加,如果父类已经包含了,可以不用写版本号 --> 15 16 <!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-hystrix --> 17 <!--feign负载均衡,后面才会用到--> 18 <dependency> 19 <groupId>org.springframework.cloud</groupId> 20 <artifactId>spring-cloud-starter-feign</artifactId> 21 </dependency> 22 23 <!--强大的lombok插件--> 24 <dependency> 25 <groupId>org.projectlombok</groupId> 26 <artifactId>lombok</artifactId> 27 </dependency> 28 29 </dependencies> 30 31 </project>
3.在api里创建一个实体类Dept.java(关于lombok使用技巧可以参考 转载:https://blog.csdn.net/wsk1103/article/details/78053994)
package com.atguigu.springcloud.entities; import lombok.Data; import lombok.NoArgsConstructor; import lombok.experimental.Accessors; import java.io.Serializable; @Data//一站式解决 //@AllArgsConstructor//全参函数 @NoArgsConstructor//无参函数 @Accessors(chain = true)//开启链式风格(非常实用) public class Dept implements Serializable { private Long deptno; // 主键 private String dname; // 部门名称 private String db_source;// 来自那个数据库,因为微服务架构可以一个服务对应一个数据库,同一个信息被存储到不同数据库 public Dept(String dname) { super(); this.dname = dname; } }
4.继续创建父工程的一个子模块8001,创建完成之后第一个步骤基本都是修改pom
1 <?xml version="1.0" encoding="UTF-8"?> 2 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 3 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4 <modelVersion>4.0.0</modelVersion> 5 6 <parent> 7 <groupId>com.atguigu.springcloud</groupId> 8 <artifactId>microservicecloud</artifactId> 9 <version>1.0-SNAPSHOT</version> 10 </parent> 11 12 <artifactId>microservicecloud-config-dept-client-8001</artifactId> 13 14 <dependencies> 15 <!-- SpringCloudConfig配置 --> 16 <dependency> 17 <groupId>org.springframework.cloud</groupId> 18 <artifactId>spring-cloud-starter-config</artifactId> 19 </dependency> 20 <dependency> 21 <groupId>org.springframework.boot</groupId> 22 <artifactId>spring-boot-starter-actuator</artifactId> 23 </dependency> 24 <dependency> 25 <groupId>org.springframework.cloud</groupId> 26 <artifactId>spring-cloud-starter-eureka</artifactId> 27 </dependency> 28 29 <!--此依赖用于引入api模块,这样可以便使用entities实体类--> 30 <dependency> 31 <groupId>com.atguigu.springcloud</groupId> 32 <artifactId>microservicecloud-api</artifactId> 33 <version>${project.version}</version> 34 </dependency> 35 36 <dependency> 37 <groupId>junit</groupId> 38 <artifactId>junit</artifactId> 39 </dependency> 40 <!--actuator监控信息完善--> 41 <dependency> 42 <groupId>org.springframework.boot</groupId> 43 <artifactId>spring-boot-starter-actuator</artifactId> 44 </dependency> 45 <dependency> 46 <groupId>mysql</groupId> 47 <artifactId>mysql-connector-java</artifactId> 48 </dependency> 49 <dependency> 50 <groupId>com.alibaba</groupId> 51 <artifactId>druid</artifactId> 52 </dependency> 53 <dependency> 54 <groupId>ch.qos.logback</groupId> 55 <artifactId>logback-core</artifactId> 56 </dependency> 57 <dependency> 58 <groupId>org.mybatis.spring.boot</groupId> 59 <artifactId>mybatis-spring-boot-starter</artifactId> 60 </dependency> 61 <dependency> 62 <groupId>org.springframework.boot</groupId> 63 <artifactId>spring-boot-starter-jetty</artifactId> 64 </dependency> 65 <dependency> 66 <groupId>org.springframework.boot</groupId> 67 <artifactId>spring-boot-starter-web</artifactId> 68 </dependency> 69 <dependency> 70 <groupId>org.springframework.boot</groupId> 71 <artifactId>spring-boot-starter-test</artifactId> 72 </dependency> 73 74 <!--热部署插件,一修改即生效--> 75 <dependency> 76 <groupId>org.springframework</groupId> 77 <artifactId>springloaded</artifactId> 78 </dependency> 79 <dependency> 80 <groupId>org.springframework.boot</groupId> 81 <artifactId>spring-boot-devtools</artifactId> 82 </dependency> 83 </dependencies> 84 </project>
。。。。。。
这个坑不好开啊啊啊