`
springcloud关注者
  • 浏览: 309621 次
  • 性别: Icon_minigender_1
  • 来自: 北京
博客专栏
12d8ea3d-4199-3941-8a17-acd5024729b8
Spring_Cloud构...
浏览量:249702
文章分类
社区版块
存档分类
最新评论

(九)整合spring cloud云服务架构 - commonservice-config配置服务搭建

阅读更多

1. 介绍

Spring Cloud Config为分布式系统中的外部配置提供服务器和客户端支持。使用Config Server,您可以在所有环境中管理应用程序的外部属性。客户端和服务器上的概念映射与Spring EnvironmentPropertySource抽象相同,因此它们与Spring应用程序非常契合,但可以与任何以任何语言运行的应用程序一起使用。随着应用程序通过从开发人员到测试和生产的部署流程,您可以管理这些环境之间的配置,并确定应用程序具有迁移时需要运行的一切。服务器存储后端的默认实现使用git,因此它轻松支持标签版本的配置环境,以及可以访问用于管理内容的各种工具。很容易添加替代实现,并使用Spring配置将其插入。

2. 引入pom相关jar包,其中pom.xml配置如下:

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<parent>
		<groupId>com.ml.honghu</groupId>
		<artifactId>commonservice</artifactId>
		<version>0.0.1-SNAPSHOT</version>
	</parent>
	
	<artifactId>commonservice-config</artifactId>
	<packaging>jar</packaging>

	<name>commonservice-config</name>
	<description>Config Server</description>

	<dependencies>
		<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>
		<dependency>
	                <groupId>org.springframework.boot</groupId>
	                <artifactId>spring-boot-starter-security</artifactId>
	        </dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
				<executions>
					<execution>
						<id>1</id>
						<goals>
							<goal>repackage</goal>
						</goals>
					</execution>
	                                <execution>
	                	                <id>2</id>
	                                        <goals>
	                                               <goal>build-info</goal>
	                                        </goals>
	                                </execution>
				</executions>
			</plugin>
		</plugins>
	</build>
</project>

 3. 在src/main/java进行ConfigApplication.java启动文件配置:

 

package com.ml.honghu;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;

@EnableConfigServer
@EnableEurekaClient
@SpringBootApplication
public class ConfigApplication {

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

 4. 在src/main/resource下进行bootstrap.yml配置

server: 
port: 8888
spring:
  application:
    name: commonservice-config-server
  profiles:
    active: discovery,native
  cloud:
    config:
      server:
        git:
          uri: http://192.168.0.254/honghu.../honghu-config.git
          username: honghu
          password: 123456
          searchPaths: config-dev
security:
  basic:
    enabled: true
  user:
    name: honghu
    password: 123456
eureka:
  client:
    serviceUrl:
      defaultZone: http://honghu:123456@localhost:8761/eureka/
      honghuZone: http://honghu:123456@localhost:8761/eureka/
    registry-fetch-interval-seconds: 300
    availability-zones:
      honghu: honghuZone
  instance:
    prefer-ip-address: true
    metadataMap:
      version: 1.0
      variant: A
      user: ${security.user.name}
      password: ${security.user.password}
management:
  security:
    enabled: false

 注意: 如果不从远程git或者svn库加载配置文件信息,可以配置加载本地地址,比如window下配置使用:

server: 
port: 8888
spring:
  application:
    name: commonservice-config-server
  profiles:
    active: discovery,native
  cloud:
    config:
      server:
        native.searchLocations: d:/honghu-config
security:
  basic:
    enabled: true
  user:
    name: honghu
    password: 123456
eureka:
  client:
    serviceUrl:
      defaultZone: http://honghu:123456@localhost:8761/eureka/
      honghuZone: http://honghu:123456@localhost:8761/eureka/
    registry-fetch-interval-seconds: 300
    availability-zones:
      honghu: honghuZone
  instance:
    prefer-ip-address: true
    metadataMap:
      version: 1.0
      variant: A
      user: ${security.user.name}
      password: ${security.user.password}
management:
  security:
    enabled: false

 

 到此,整个config服务项目配置完毕!!

 

从现在开始,我这边会将近期研发的spring cloud微服务云架构的搭建过程和精髓记录下来,帮助更多有兴趣研发spring cloud框架的朋友,大家来一起探讨spring cloud架构的搭建过程及如何运用于企业项目。

 

 

5
0
分享到:
评论
2 楼 springcloud关注者 2017-10-18  
jxgaly 写道
紧跟文章,期待后续文章的分享!

马上会有新的文章出来
1 楼 jxgaly 2017-10-18  
紧跟文章,期待后续文章的分享!

相关推荐

    eureka分布式微服务

    其中,Eureka是Spring Cloud中的服务发现组件,它能够实现服务注册与发现的功能,是分布式微服务架构中不可或缺的一部分。 #### 二、创建Eureka服务发现中心 根据给定的文件信息,我们将详细介绍如何创建一个名为`...

    鸿鹄Cloud分布式微服务云系统管理_springcloud_分布式_产品_云_平台_

    Commonservice-system 是一个大型分布式、微服务、面向企业的 JavaEE 体系快速研发平台,基于模块化、服务化、原子化、热插拔的设计思想,使用成熟领先的无商业限制的主流开源技术构建。 采用服务化的组件开发模式,...

    spring cloud consul使用ip注册服务的方法示例

    其次,我们需要添加 `instance-id` 属性,并将其设置为 `${spring.application.name}:${spring.cloud.client.ip-address}`。这将使 Consul 使用 IP 地址来注册服务。 ```yaml spring: cloud: consul: host: xxx....

    unity对接网狐服务器文档

    - 公共服务(CommonService):提供基础服务支持,需优先编译。 - 网络服务(NetService):处理网络通信,用于登录服务器和游戏服务器,同样需要优先编译。 - 列表服务(ListService)、内核引擎(KernelEngine...

    17.5、利用反射调用webservice1

    在本例中,Spring用于管理对象生命周期和配置。 - 创建`IWsService`接口,其中包含一个方法`getWsDestInfoByKey`,用于根据键获取Web Service信息。 - 实现`IWsService`的`WsServiceImp`类,使用`@Service`注解...

    大数据分析系统

    - **AppConfig**: 配置类,用于存储系统级的配置信息,如`List_PageSize`。 - **PageBean**: 分页相关的类,可能包含了当前页码、每页显示记录数等属性。 - **HashMapValue**: 用于存储键值对的自定义类或枚举类型。...

    javaconfig

    JavaConfig是Spring框架中的一种配置方式,它使用Java代码来替代XML配置,使得应用程序的配置更加简洁、可读性更强,同时也更易于测试和维护。这个"javaconfig"主题主要涵盖了Spring框架的Java配置特性,以及如何在...

    Spring循环依赖报错Bean with name ‘**’ has been injected into other beans [**] in its raw version as part

    在Spring框架中,循环依赖(Circular Dependency)是指两个或多个Bean之间形成的一种相互依赖关系,导致Spring容器在初始化这些Bean时遇到困难。当一个Bean依赖于另一个Bean,而后者又反过来依赖于前者,就会出现...

    2、webservice--常用注解1

    在上面的配置中,我们定义了一个名为 `commonWS` 的WebService,服务类为 `org.dsp.ea.pay.ws.ICommonWS`,服务地址为 `/CommonService`。同时,我们还指定了 `commonWSImp` bean 作为服务实现类。 这篇文章详细...

    .NET Core 3.0之创建基于Consul的Configuration扩展组件

    在Consul的UI界面中,可以设置commonservice和userservice等服务的配置信息,并且通过Consul的KV存储功能来维护这些配置。 最后,创建基于Consul的Configuration扩展组件需要考虑的不仅仅是技术实现,还包括了配置...

    hibernate链接oracle

    最后,定义了两个业务服务bean:`BWService`和`CommonService`。这两个服务均使用了上面定义的事务代理工厂,并关联了具体的实现类。 - `target`: 实际调用的业务逻辑bean,如`BWServiceTarget`和`CommonTarget`。 ...

    java毕设项目之基于java+springboot科研工作量管理系统的设计与实现.zip

    项目中还包含了一些通用的服务和控制器,比如`CommonService.java`和`GongzuoliangController.java`,这些类通常用于实现业务逻辑,处理来自前端的请求,并调用DAO层操作数据库。`CommonUtil.java`可能是包含了一些...

    angular4 共享服务在多个组件中数据通信的示例

    providers: [CommonService] // 在父组件中提供服务 }) export class ParentComponent implements OnInit { public list: any = []; constructor(private commonService: CommonService) { this.list = ...

    Angular父子组件以及非父子组件之间的通讯.pdf

    constructor(private commonService: CommonService) { } sendData() { this.commonService.setData('data from A'); } } export class ComponentB implements OnInit { constructor(private commonService: ...

    common-service

    共同服务Clojure库旨在...好的,这取决于您。测验clj -M:test用法整我执照版权所有:copyright:2020 FIXME 该程序和随附的材料根据Eclipse Public License 2.0的条款提供,该条款可从。 当满足Eclipse Public License...

    基于Android平台的教师课堂智能助手系统.pdf

    蓝牙服务继承自CommonService类,需要重写Runnable接口。 五、实现细节 在实现中,我们使用了HashMap来存储学生的信息,并使用蓝牙套接字来实现数据传输。在发送端,我们使用学生的信息来创建一个HashMap,并将其...

    angular中的http拦截器Interceptors的实现

    Interceptors 有两个处理时机,分别是: ... 得到请求的响应之后,在交给其它程序代码处理之前,即处理请求的响应 其引用场景包括 ...commonService.config(['$httpProvider',function($httpProvider){ //$h

    商城.zip_Java_

    1. SysConfigService.java:这可能是用于管理系统配置的服务,包括获取和更新系统级别的参数,这对于商城的动态配置和个性化设置至关重要。 2. BizOrderService.java、BizOrderExpressService.java、...

Global site tag (gtag.js) - Google Analytics