(Forty-three) spring cloud micro Services Architecture b2b2c integrate e-commerce -eureka cluster config configuration center

Please add source e-commerce platform Penguin beg: 3536247259. Join dependence

<dependencies>
   <!-- 监控 -->
   <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-actuator</artifactId>
   </dependency>

   <!-- 安全验证 -->
   <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-security</artifactId>
   </dependency>

   <!-- Netflix -->
   <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-config-server</artifactId>
   </dependency>
   <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-eureka</artifactId>
   </dependency>
</dependencies>


application.yml

server:
  port: 8881

spring:
  application:
    name: tms-config
  cloud:
    config:
      server:
        git:
          uri: 仓库地址
          searchPaths: 目录
          username: 用户名
          password: 密码
      label: master

eureka:
  instance:
    prefer-ip-address: true
    lease-renewal-interval-in-seconds: 30
    lease-expiration-duration-in-seconds: 90
    metadata-map:
      name: tms-config-metadata-map-name
  client:
    serviceUrl:
      defaultZone: http://admin:[email protected]:8761/eureka/, http://admin:[email protected]:8762/eureka/
    # 抓取服务列表时间间隔
    registry-fetch-interval-seconds: 30

endpoints:
  sensitive: false
  shutdown:
    enabled: true
    sensitive: true

security:
  user:
    name: admin
    password: admin
    role: SUPERUSER

management:
  context-path: /tms-config
  security:
    roles: SUPERUSER #角色

# 日志
logging:
  file: logs/logger.log
  level:
    com.netflix: DEBUG
    org.springframework.web: DEBUG
    org.springframework.security: INFO

Startup Items

@SpringBootApplication
@EnableConfigServer
@EnableEurekaClient
public class TmsConfigApplication {

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

The caller configuration, pay attention here to use this profile name bootstrap.yml

spring:
  application:
    name: tms-client
  cloud:
    config:
      label: master
      profile: dev
      username: admin
      password: admin
      discovery:
        enabled: true
        service-id: tms-config

eureka:
  client:
    serviceUrl:
      defaultZone: http://admin:[email protected]:8761/eureka/, http://admin:[email protected]:8762/eureka/

Reads the configuration file content


@RestController
public class TestController {

    @Value("${apuserName}")
    private String apuserName;

    @GetMapping(value = "/hello")
    public String hello() {
        return apuserName;
    }
}

Guess you like

Origin blog.csdn.net/wiyzq/article/details/91045718