美文网首页
Java版Spring Cloud B2B2C o2o社交电商-

Java版Spring Cloud B2B2C o2o社交电商-

作者: IT小跑兵 | 来源:发表于2019-07-23 10:29 被阅读0次

    电子商务平台源码请加企鹅求求:三五三六二四七二五九。一 创建一个Spring Boot工程,命名为eureka-server,并在pom.xml中引入必要的依赖,代码如下。

        <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>
    

    二 通过@EnableEurekaServer注解启动一个服务注册中心提供给其他应用程序进行对话,只需要在Spring Boot应用中添加下面这个注解就能开启此功能。

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

    三 在默认情况下,服务注册中也会将自己作为客户端来尝试注册它自己,所以需要禁用它的客户端行为。

    application.properties中增加如下配置。

    spring.application.name=eureka-server
    server.port=1111
     
    eureka.instance.hostname=localhost
     
    # 关闭保护机制
    #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
    

    说明:
    eureka.client.register-with-eureka:由于该应用为注册中心,所以设置为false,代表不向注册中心注册自己。

    eureka.client.fetch-registry:由于注册中心的职责就是维护服务实例,它并不需要去检索服务,所以也设置为false。

    相关文章

      网友评论

          本文标题:Java版Spring Cloud B2B2C o2o社交电商-

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