美文网首页
1、创建SpringCloud server管理者

1、创建SpringCloud server管理者

作者: SmartBin | 来源:发表于2019-05-30 16:43 被阅读0次

    创建一个SpringBoot项目,作为SpringCloud服务管理者,使用eureka框架,其它服务通过注册,成为一个微服务。

    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.smartbin</groupId>
        <artifactId>springserver</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <name>springserver</name>
        <description>Demo project for Spring Boot</description>
        <packaging>jar</packaging>
    
        <!--使用SpringBoot1.5.3版本-->
       <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>1.5.3.RELEASE</version>
            <relativePath/> <!-- lookup parent from repository -->
        </parent>
    
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
            <java.version>1.8</java.version>
        </properties>
    
        <dependencies>
    
            <!--开启eureka服务注册功能-->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-eureka-server</artifactId>
            </dependency>
    
            <!--======== SpringBoot的配置start ===========-->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
    
        </dependencies>
    
        <dependencyManagement>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.cloud</groupId>
                    <artifactId>spring-cloud-dependencies</artifactId>
                    <version>Camden.SR7</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>
    
    

    application.yml配置

    server:
      port: 8000
    
    eureka:
      instance:
        hostname: 0.0.0.0
      client:
        #以下两个作用是禁止自己注册到服务中心
        register-with-eureka: false
        fetch-registry: false
        serviceUrl:
          #指定客服端调用的服务地址
          defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka
    
    

    在启动类上添加 @EnableEurekaServer 注解

    @EnableEurekaServer    //启用服务中心
    @SpringBootApplication
    public class SpringserverApplication {
    
       public static void main(String[] args) {
           SpringApplication.run(SpringserverApplication.class, args);
       }
    
    }
    

    该项目构建完成,在浏览器中输入 http://localhost:8000/ ,即可进入服务管理页面,可查看已经注册的服务

    相关文章

      网友评论

          本文标题:1、创建SpringCloud server管理者

          本文链接:https://www.haomeiwen.com/subject/iievtctx.html