Spring Cloud Config Setup illustration example (iv)-Supplemental configuration file

Source: Internet
Author: User

Service-Side Configserverpom.xml
        <dependency>            <groupId>Org.springframework.cloud</groupId>            <artifactId>Spring-cloud-config-server</artifactId>        </dependency>                <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>

What is the difference between Spring-cloud-starter-eureka and spring-cloud-starter-eureka-server?

App class
@EnableDiscoveryClient@EnableConfigServerpublic class ConfigServerApplication {    public static void main(String[] args) {        SpringApplication.run(ConfigServerApplication.class, args);    }}

What is the difference between @EnableDiscoveryClient and @enableeurekaclient?

Application.yml
server:   port: ${PORT:8888}                                #配置工程端口号spring:   application:      name: cloud-config-server                     #设置该服务应用名称   profiles:      active: native                                 #设置读取为本地工程文件   config:      server:         native:            searchLocations: classpath:/config       #配置文件根目录,也就是XXX-dev.properties等的目录#注册到eureka服务中心进行监控eureka:   client:      serviceUrl:          defaultZone: http://eureka:[email protected]:8761/eureka # 可以逗号分隔,配置多个      healthcheck:          enabled: true                                                         #开启健康监控   instance:      prefer-ip-address: true      instanceId: ${spring.application.name}:${spring.application.instance_id:${server.port}}      leaseRenewalIntervalInSeconds: 30       leaseExpirationDurationInSeconds: 90

The official website also uses the hair to send the hair this port.

Configuration file

Config directory under configuration file:
Xxx-dev.properties
Xxx-test.properties

db.type=com.alibaba.druid.pool.DruidDataSourcedb.driverClassName=com.mysql.jdbc.Driverdb.url=jdbc:mysql://localhost:3306/MYDB?useUnicode=true&characterEncoding=UTF8db.username=dbuserdb.password=123456
Client Appclientpom.xml also need to add autuator
    <dependency>        <groupId>org.springframework.boot</groupId>        <artifactId>spring-boot-starter-web</artifactId>    </dependency>    <dependency>        <groupId>org.springframework.cloud</groupId>        <artifactId>spring-cloud-starter-config</artifactId>    </dependency>        <dependency>        <groupId>org.springframework.cloud</groupId>        <artifactId>spring-cloud-starter-eureka</artifactId>    </dependency>    <dependency>        <groupId>org.springframework.boot</groupId>        <artifactId>spring-boot-starter-actuator</artifactId>    </dependency>
Bootstrap.properties Configuration
spring.cloud.config.name=XXXspring.cloud.config.profile=dev#spring.cloud.config.profile=testspring.cloud.config.uri=http\://localhost\:8888/ # 只能配置一个,不能逗号分隔配置多个config
APPLICATION.YML Configuration
server:   port: 8080                                  #设置当前服务端口   context-path: /abc                          #设置服务上下文路径spring:   application:      name: app-client                  #service name 设置当前服务名称eureka:   client:      serviceUrl:          defaultZone: http://eureka:[email protected]:8761/eureka   # 可以逗号分隔,配置多个      healthcheck:          enabled: true   instance:      prefer-ip-address: true                              # 注册到Eureka Server上的是IP      instanceId: ${spring.application.name}:${spring.application.instance_id:${server.port}}      leaseRenewalIntervalInSeconds: 15                    # 心跳时间,即服务续约间隔时间(缺省为30s)        leaseExpirationDurationInSeconds: 45                  # 发呆时间,即服务续约到期时间(缺省为90s)
Application class
@SpringBootApplication@EnableEurekaClientpublicclass ClientApplication {    publicstaticvoidmainthrows Exception {        SpringApplication.run(ClientApplication.class, args);    }}

Resources:
Spring Cloud Config Illustration example (iii)
Example of Spring Cloud Config Setup (ii)

Spring Cloud Config Setup illustration example (iv)-Supplemental configuration file

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.