Java B2B2C多用户商城 springcloud架构 --Eureka服务器搭建及配置

第一步,建立一个普通的springboot项目java

如下方法均可以快速建立一个boot项目: web

1. 浏览器访问http://start.spring.io/,填写信息,下载zip包,加压到你的ide的工做空间直接使用。 spring

2. 使用idea自动生成boot项目 apache

3. 使用eclipse建立boot项目 浏览器

须要JAVA Spring Cloud大型企业分布式微服务云构建的B2B2C电子商务平台源码 一零三八七七四六二六安全

第二步,在pom.xml中添加依赖(如下是个人完整依赖)springboot

<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/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <groupId>com.eureka.server</groupId>
    <artifactId>eureka-server-001</artifactId>
    <version>0.0.1</version>
    <name>eureka-server-001 Maven Webapp</name>
    <url>http://maven.apache.org</url>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.4.RELEASE</version>
        <relativePath />
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <spring-cloud.version>Dalston.SR4</spring-cloud.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <!-- Spring Cloud 基础数据添加 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka-server</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-netflix-core</artifactId>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
        </dependency>
        <!-- 热部署插件 -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>springloaded</artifactId>
        </dependency>
        <!-- 热部署 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
        </dependency>
        <!--spring boot admin -->
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-client</artifactId>
            <version>1.3.2</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>
        <!--  安全认证-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</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-dev.properties将application.properties文件名称修改成application-dev.properties。
 app

#appname默认
spring.application.name=Eureka-H.A.
#注册端口号
server.port=8761

#-----------------------编写者相关信息----------------------
#-----------------------编写者相关信息----------------------
info.owner=LTY
info.version=@project.version@
info.app.name=@project.name@
info.app.version=@project.version@
info.app.description=@project.description@
info.app.spring-boot-version=@project.parent.version@

#安全认证
security.basic.enabled=false
security.user.name=admin
security.user.password=123456

spring.boot.admin.url=http://localhost:8080
#------------------------服务与发现相关信息---------------------
#------------------------服务与发现相关信息---------------------
#不使用主机名来定义注册中心的地址,而使用IP地址的形式,若是设置了属性,则使用该属性配置的IP,不然自动获取除环路IP外的第一个IP地址
# 注册时显示ip
eureka.instance.prefer-ip-address=true
#IP地址
#eureka.instance.ip-address=localhost
#是否注册为服务
eureka.client.register-with-eureka=false
#是否检索服务
eureka.client.fetch-registry=false
#设置当前实例的主机名称
eureka.instance.hostname=localhost
#定义服务续约任务(心跳)的调用间隔,单位:秒
eureka.instance.lease-renewal-interval-in-seconds=30
#定义服务失效的时间,单位:秒
eureka.instance.lease-expiration-duration-in-seconds=90
#状态页面的URL,相对路径,默认使用 HTTP 访问,若是须要使用 HTTPS则须要使用绝对路径配置
eureka.instance.status-page-url-path=/info
#健康检查页面的URL,相对路径,默认使用 HTTP 访问,若是须要使用 HTTPS则须要使用绝对路径配置
eureka.instance.health-check-url-path=/health
#健康检查页面的URL,绝对路径
eureka.instance.health-check-url=/
#关闭注册中心的保护机制,Eureka 会统计15分钟以内心跳失败的比例低于85%将会触发保护机制,不剔除服务提供者,若是关闭服务注册中心将不可用的实例正确剔除
#关闭自我保护(生产时打开该选项)
eureka.server.enable-self-preservation=true
#扫描失效服务的间隔时间(缺省为60*1000ms)
eureka.server.eviction-interval-timer-in-ms=5000
#eureka默认空间的地址
eureka.client.service-url.defaultZone=http://localhost:8761/eureka/


第四步,添加application.yml
 eclipse

spring: 
  profiles: 
    active: dev



第五步,修改Application类maven

添加注解 

@EnableEurekaServer 该注解代表应用为eureka服务,有能够联合多个服务做为集群,对外提供服务注册以及发现功能 

@SpringBootApplication(建立完的boot项目自带的启动注解,会加载一些配置)

修改main() 方法
 

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

启动Application类,配置完成!

相关文章
相关标签/搜索