Spring cloud Greenwich Eureka

1、父工程POM文件中:

    <dependencyManagement>
        <dependencies>
            <!--spring cloud-->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Greenwich.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <repositories>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

  这里需要注意的是,一般的依赖都可以从Maven Repository中导入,但是spring cloud dependencies现在在里面是找不到的了。

  所以,在pom文件内,自己指定了远程仓库(通过代码中repositroy配置),远程仓库地址:https://repo.spring.io/milestone/,在这个里面你是可以找到最新的springcloud的各个依赖的,这里截取部分:

可以看到,当前最新的版本是Greewich.SR1,今年1月22日更新的。我选择的是之前一点的版本也是现在spring官网的最新推荐版本Greewich.RELEASE,各取所需吧。

2、导入依赖之后,新建子模块Eureka-server,pom文件:

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!--Netflix Eureka服务端-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
</dependencies>

3、配置文件application.yml:

spring:
  application:
    name: eureka-server
# 自己设置一个端口号,方便之后访问
server:
  port: 6543
# Eureka-server的简单配置
eureka:
  instance:
    hostname: 127.0.0.1 
  client:
    register-with-eureka: false
    fetch-registry: false

4、新建启动类Application并配置开启服务:

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

5、启动服务查看服务:

Eureka的服务端配置完成。

扫描二维码关注公众号,回复: 5883834 查看本文章

个人能力有限,欢迎交流学习,帮助指明错误,希望转载注明出处,谢谢。

猜你喜欢

转载自www.cnblogs.com/dlfming/p/10704651.html