spring cloud系列-01.注册中心Eureka搭建

来源:互联网 发布:手机做表格软件 编辑:程序博客网 时间:2024/06/03 18:56

最近项目中用到了spring cloud中的整套东西,刚好闲下来总结下整套框架的搭建过程。
废话不多说,先看注册中心的搭建配置。

1.pom.xml应用spring cloud的相关jar包:

  <parent>      <groupId>org.springframework.boot</groupId>        <artifactId>spring-boot-starter-parent</artifactId>        <version>1.5.4.RELEASE</version>     </parent>     <dependencyManagement>    <dependencies>         <dependency>             <groupId>org.springframework.cloud</groupId>             <artifactId>spring-cloud-dependencies</artifactId>             <version>Dalston.SR1</version>             <type>pom</type>             <scope>import</scope>         </dependency>     </dependencies>    </dependencyManagement>  <properties>    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  </properties>  <dependencies>      <!--eureka server 注册中心服务jar包 -->        <dependency>            <groupId>org.springframework.cloud</groupId>            <artifactId>spring-cloud-starter-eureka-server</artifactId>        </dependency>        <!-- 添加monitor监控,可忽略 -->        <dependency>            <groupId>de.codecentric</groupId>            <artifactId>spring-boot-admin-starter-client</artifactId>            <version>1.3.4</version>        </dependency>        <dependency>            <groupId>org.springframework.boot</groupId>            <artifactId>spring-boot-starter-actuator</artifactId>        </dependency>        <dependency>            <groupId>org.jolokia</groupId>            <artifactId>jolokia-core</artifactId>        </dependency>  </dependencies>    <build>        <plugins>            <plugin>                <groupId>org.springframework.boot</groupId>                <artifactId>spring-boot-maven-plugin</artifactId>            </plugin>             <plugin>                  <groupId>org.apache.maven.plugins</groupId>                  <artifactId>maven-compiler-plugin</artifactId>                  <configuration>                      <source>1.8</source>                      <target>1.8</target>                  </configuration>              </plugin>          </plugins>    </build>

2.application.properties配置(习惯了properties格式的文件,一直没有使用yml格式的文件)

#####################本应用端口及名称spring.application.name=registry-serverserver.port=8761eureka.client.registerWithEureka=falseeureka.client.fetchRegistry=falseeureka.client.serviceUrl.defaultZone=http://127.0.0.1:8761/eureka/# ===================================================================# 服务监控中心配置 (可忽略)# ===================================================================spring.boot.admin.client.enabled=truespring.boot.admin.client.name=registry-serverspring.boot.admin.url=http://127.0.0.1:8090spring.boot.admin.client.prefer-ip=truespring.boot.admin.client.service-url=http://127.0.0.1:8761#spring.boot.admin.client.health-url=http://127.0.0.1:8773info.app.name="@project.name@"info.app.description="registry-server"info.app.version="@project.version@"info.app.spring-boot-version="@project.parent.version@"management.security.enabled=false

3.spring boot启动类

import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;/** * 服务启动入口 * */@EnableEurekaServer@SpringBootApplicationpublic class RegistryServerApplication {    public static void main(String[] args) {        SpringApplication.run(RegistryServerApplication.class, args);    }}

4.启动启动类,即可看到效果,简单的注册中心搭建完成
注册中心效果图

阅读全文
0 0
原创粉丝点击