Javaa B2B2C Source E-Commerce Platform--Building Eureka Registry

Keywords: Java Spring xml

First, create a Spring Boot project, named eureka-server, and introduce the necessary dependencies in pom.xml. The code is as follows. Friends who are willing to know the source code ask for communication and sharing technology directly: 21477 75633


    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.3.7.RELEASE</version>
        <relativePath/>
    </parent>
 
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
    </properties>
 
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka-server</artifactId>
        </dependency>
 
        <!--<dependency>-->
            <!--<groupId>org.springframework.boot</groupId>-->
            <!--<artifactId>spring-boot-starter-actuator</artifactId>-->
        <!--</dependency>-->
    </dependencies>
 
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Brixton.SR5</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

Second, start a service registry for dialogue with other applications through the @Enable Eureka Server annotation, which can be turned on by simply adding the following annotation to the Spring Book application.


@EnableEurekaServer
@SpringBootApplication
public class Application {
 
    public static void main(String[] args) {
        new SpringApplicationBuilder(Application.class).web(true).run(args);
    }
 
}

Third, by default, the service registry will try to register itself as a client, so it needs to disable its client behavior.

Add the following configuration in application.properties.


spring.application.name=eureka-server
server.port=1111
 
eureka.instance.hostname=localhost
 
# Shut down the protection mechanism
#eureka.server.enable-self-preservation=false
 
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
eureka.client.serviceUrl.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka/
 
logging.file=${spring.application.name}.log

Explain:
eureka.client.register-with-eureka: Since the application is a registry, it is set to false, meaning that it does not register itself with the registry.
eureka.client.fetch-registry: Since the registry's responsibility is to maintain service instances, it does not need to retrieve services, so it is also set to false.
The overall code structure is as follows: Data and Source Sources 

Posted by getmizanur on Mon, 21 Jan 2019 16:36:13 -0800