springCloud版本介绍
springCloud由于是多个子项目的合集,为了方便区分,所以采用伦敦地铁站的名称作为版本号,是按照A-Z的字母顺序排列的:
cloud版本 | boot版本 |
---|---|
Angel | 1.2.x |
Brixton | 1.3.x |
Camden | 1.4.x |
Dalston、Edgware | 1.5.x |
Finchley | 2.2.x |
我选择的版本如下:
springCloud
Finchley.RELEASE
新建maven父项目
1.1 点击File-New-Project
1.2 我们选择maven,选好SDk后,点击next。
1.3 填写GroupId、ArtifactId、Version信息,点击Next
1.4 输入Project Name 和Project location 点击Finish
1.5 生成后的项目 我们需要对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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.thdz</groupId>
<artifactId>ronger</artifactId>
<version>1.0-SNAPSHOT</version>
<!--由于是父项目 将此值设置为pom-->
<packaging>pom</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
<relativePath/>
</parent>
<!--配置参数信息-->
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Finchley.RELEASE</spring-cloud.version>
</properties>
<!--添加springBoot依赖-->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</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>
</plugins>
</build>
</project>
1.6 因为是父项目,所以我们将src目录删除
1.7 在项目上右键点击,New-Module,我们新建一个Eureka Server
1.8 此时选择Spring Initialalizr ,点击Next
1.9 输入一些常用信息,点击Next
1.10 此时选择spring Cloud Discovery,勾选Eureka server
1.11 点击Finish
1.12 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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.thdz.ronger</groupId>
<artifactId>eureka-server</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>eureka-server</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>com.thdz</groupId>
<artifactId>ronger</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
</dependencies>
</project>
1.13 在EurekaServerApplication 中配置注解@EnableEurekaServer,告诉容器这是eureka服务端
package com.thdz.ronger.eurekaserver;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
}
}
1.14 修改配置文件,配置端口信息,我这里选择yml配置文件,端口是8100,以后的服务都往后顺延
server:
port: 8100
eureka:
instance:
hostname: localhost
client:
registerWithEureka: false
fetch-registry: false
service-url:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
spring:
application:
name: eureka-server