编程语言   发布时间:2022-06-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了springboot eureka 入门大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

1.eureka服务器端

2.eureka客户端

3.客户端间的通信

 

1.eureka服务器端

 1.引入依赖

2.eureka配置

3.启动,加注解

4.浏览器打开:

localhost:6868/

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLscheR_241_11845@a-instance"
         xsi:scheR_241_11845@aLOCATIOn@H_197_23@="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.ligy</groupId>
    <artifactId>eurekademo1</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>eurekademo1</name>
    <description>Demo project for@H_197_23@ Spring Boot</description>
    <properties>
        <java.version>1.8</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporTing.outputEncoding>UTF-8</project.reporTing.outputEncoding>
        <spring-boot.version>2.3.7.RELEASE</spring-boot.version>
        <spring-cloud.version>Hoxton.SR9</spring-cloud.version>
    </properties>
    <dependencymanagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import@H_197_23@</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${spring-boot.version}</version>
                <type>pom</type>
                <scope>import@H_197_23@</scope>
            </dependency>
        </dependencies>
    </dependencymanagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>
server.port=6868
#eureka配置
eureka.client.registerWithEureka@H_197_23@=false@H_197_23@
eureka.client.fetchRegistry@H_197_23@=false@H_197_23@
eureka.client.serviceUrl.defaultZone@H_197_23@=http://@H_197_23@127.0.0.1:${server.port}/eureka/@H_197_23@
package@H_197_23@ com.ligy.demo;

@H_197_23@import@H_197_23@ org.springframework.boot.SpringApplication;
@H_197_23@import@H_197_23@ org.springframework.boot.autoconfigure.SpringBootApplication;
@H_197_23@import@H_197_23@ org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@SpringBootApplication
@EnableEurekaServer
@H_197_23@public@H_197_23@ class@H_197_23@ DemoApplication {

    @H_197_23@public@H_197_23@ static@H_197_23@ void@H_197_23@ main(String[] args) {
        SpringApplication.run(DemoApplication.@H_197_23@class@H_197_23@, args);
    }

}@H_197_23@
package@H_197_23@ com.ligy.demo.controller;

@H_197_23@import@H_197_23@ org.springframework.web.bind.Annotation.requestMapping;
@H_197_23@import@H_197_23@ org.springframework.web.bind.Annotation.RestController;

@RestController
@requestMapping(@H_197_23@"/student")
@H_197_23@public@H_197_23@ class@H_197_23@ studentController {
    @requestMapping(@H_197_23@"/test")
    @H_197_23@public@H_197_23@ String test() {
        @H_197_23@return@H_197_23@ "你好,世界";
    }
}@H_197_23@

springboot eureka 入门

 

 

 

springboot eureka 入门

 

 

 

2.eureka客户端

 1.引入依赖

2.eureka配置

3.启动,加注解

4.浏览器打开:

localhost:6868/

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLscheR_241_11845@a-instance"
         xsi:scheR_241_11845@aLOCATIOn@H_197_23@="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.ligy</groupId>
    <artifactId>eurekademo2</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>eurekademo2</name>
    <description>Demo project for@H_197_23@ Spring Boot</description>
    <properties>
        <java.version>1.8</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporTing.outputEncoding>UTF-8</project.reporTing.outputEncoding>
        <spring-boot.version>2.3.7.RELEASE</spring-boot.version>
        <spring-cloud.version>Hoxton.SR9</spring-cloud.version>
    </properties>
    <dependencymanagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import@H_197_23@</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${spring-boot.version}</version>
                <type>pom</type>
                <scope>import@H_197_23@</scope>
            </dependency>
        </dependencies>
    </dependencymanagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>
server.port=8085
spring.application.name@H_197_23@=eurekademo2
#eureka配置
#eureka.client.registerWithEureka@H_197_23@=false@H_197_23@
#eureka.client.fetchRegistry@H_197_23@=false@H_197_23@
eureka.client.serviceUrl.defaultZone@H_197_23@=http://@H_197_23@127.0.0.1:6868/eureka/@H_197_23@
eureka.instance.prefer-ip-address=true@H_197_23@
server.port=8086
spring.application.name@H_197_23@=eurekademo3
#eureka配置
#eureka.client.registerWithEureka@H_197_23@=false@H_197_23@
#eureka.client.fetchRegistry@H_197_23@=false@H_197_23@
eureka.client.serviceUrl.defaultZone@H_197_23@=http://@H_197_23@127.0.0.1:6868/eureka/@H_197_23@
eureka.instance.prefer-ip-address=true@H_197_23@
server.port=8087
spring.application.name@H_197_23@=eurekademo4
#eureka配置
#eureka.client.registerWithEureka@H_197_23@=false@H_197_23@
#eureka.client.fetchRegistry@H_197_23@=false@H_197_23@
eureka.client.serviceUrl.defaultZone@H_197_23@=http://@H_197_23@127.0.0.1:6868/eureka/@H_197_23@
eureka.instance.prefer-ip-address=true@H_197_23@
package@H_197_23@ com.ligy.demo;

@H_197_23@import@H_197_23@ org.springframework.boot.SpringApplication;
@H_197_23@import@H_197_23@ org.springframework.boot.autoconfigure.SpringBootApplication;
@H_197_23@import@H_197_23@ org.springframework.cloud.netflix.eureka.EnableEurekaClient;

@SpringBootApplication
@EnableEurekaClient
@H_197_23@public@H_197_23@ class@H_197_23@ DemoApplication {

    @H_197_23@public@H_197_23@ static@H_197_23@ void@H_197_23@ main(String[] args) {
        SpringApplication.run(DemoApplication.@H_197_23@class@H_197_23@, args);
    }

}@H_197_23@

 

springboot eureka 入门

 

 

 

springboot eureka 入门

 

 

 

springboot eureka 入门

 

 

 

3.客户端间的通信

1.注解

@EnableDiscoveryClient@EnableFeignClients

2.新增接口

package@H_197_23@ com.ligy.demo.service;

@H_197_23@import@H_197_23@ org.springframework.cloud.openfeign.FeignClient;
@H_197_23@import@H_197_23@ org.springframework.web.bind.Annotation.requestMapping;

@FeignClient(@H_197_23@"eurekademo2")
@H_197_23@public@H_197_23@ interface@H_197_23@ Demo2Serive {

    @requestMapping(@H_197_23@"/demo2/test")
    String test();
}@H_197_23@

3.新增控制器方法

package@H_197_23@ com.ligy.demo.controller;

@H_197_23@import@H_197_23@ com.ligy.demo.service.Demo2Serive;
@H_197_23@import@H_197_23@ org.springframework.beans.factory.Annotation.Autowired;
@H_197_23@import@H_197_23@ org.springframework.web.bind.Annotation.requestMapping;
@H_197_23@import@H_197_23@ org.springframework.web.bind.Annotation.RestController;

@RestController
@requestMapping(@H_197_23@"/demo4")
@H_197_23@public@H_197_23@ class@H_197_23@ studentController {
    @Autowired
    Demo2Serive demo2Serive;

    @requestMapping(@H_197_23@"/demo2test")
    @H_197_23@public@H_197_23@ String demo2test() {

        @H_197_23@return@H_197_23@ demo2Serive.test();
    }

    @requestMapping(@H_197_23@"/test")
    @H_197_23@public@H_197_23@ String test() {
        @H_197_23@return@H_197_23@ "你好,世界demo4";
    }
}@H_197_23@

 

 

 


package@H_197_23@ com.ligy.demo;

@H_197_23@import@H_197_23@ org.springframework.boot.SpringApplication;
@H_197_23@import@H_197_23@ org.springframework.boot.autoconfigure.SpringBootApplication;
@H_197_23@import@H_197_23@ org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@H_197_23@import@H_197_23@ org.springframework.cloud.netflix.eureka.EnableEurekaClient;
@H_197_23@import@H_197_23@ org.springframework.cloud.openfeign.EnableFeignClients;

@SpringBootApplication
@EnableEurekaClient
@EnableDiscoveryClient
@EnableFeignClients
@H_197_23@public@H_197_23@ class@H_197_23@ DemoApplication {

    @H_197_23@public@H_197_23@ static@H_197_23@ void@H_197_23@ main(String[] args) {
        SpringApplication.run(DemoApplication.@H_197_23@class@H_197_23@, args);
    }

}@H_197_23@

 

 

springboot eureka 入门

 

大佬总结

以上是大佬教程为你收集整理的springboot eureka 入门全部内容,希望文章能够帮你解决springboot eureka 入门所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。