CN110795135A - A method and apparatus for realizing annotated configuration - Google Patents
A method and apparatus for realizing annotated configuration Download PDFInfo
- Publication number
- CN110795135A CN110795135A CN201810863084.XA CN201810863084A CN110795135A CN 110795135 A CN110795135 A CN 110795135A CN 201810863084 A CN201810863084 A CN 201810863084A CN 110795135 A CN110795135 A CN 110795135A
- Authority
- CN
- China
- Prior art keywords
- value
- key
- configkey
- configpath
- configuration
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Granted
Links
- 238000000034 method Methods 0.000 title claims abstract description 34
- 238000004590 computer program Methods 0.000 claims description 9
- 230000001360 synchronised effect Effects 0.000 claims description 4
- 238000006243 chemical reaction Methods 0.000 abstract description 5
- 235000010627 Phaseolus vulgaris Nutrition 0.000 description 12
- 244000046052 Phaseolus vulgaris Species 0.000 description 12
- 238000010586 diagram Methods 0.000 description 11
- 230000008569 process Effects 0.000 description 9
- 238000004891 communication Methods 0.000 description 7
- 230000006870 function Effects 0.000 description 7
- 238000012545 processing Methods 0.000 description 6
- 230000003287 optical effect Effects 0.000 description 4
- 238000013461 design Methods 0.000 description 3
- 238000012986 modification Methods 0.000 description 3
- 230000004048 modification Effects 0.000 description 3
- 230000008878 coupling Effects 0.000 description 2
- 239000000835 fiber Substances 0.000 description 2
- 238000012805 post-processing Methods 0.000 description 2
- 230000000644 propagated effect Effects 0.000 description 2
- 239000004065 semiconductor Substances 0.000 description 2
- 230000003068 static effect Effects 0.000 description 2
- 230000009286 beneficial effect Effects 0.000 description 1
- 238000010276 construction Methods 0.000 description 1
- 238000010168 coupling process Methods 0.000 description 1
- 238000005859 coupling reaction Methods 0.000 description 1
- 230000000694 effects Effects 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
- 239000004973 liquid crystal related substance Substances 0.000 description 1
- 239000013307 optical fiber Substances 0.000 description 1
- 238000012954 risk control Methods 0.000 description 1
- 238000006467 substitution reaction Methods 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/70—Software maintenance or management
- G06F8/71—Version control; Configuration management
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/70—Software maintenance or management
- G06F8/73—Program documentation
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- General Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Library & Information Science (AREA)
- Computer Security & Cryptography (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
本发明公开了实现注解式配置的方法和装置,涉及计算机技术领域。该方法的一具体实施方式包括:读读取配置文件,以实现环境设置;创建组件工厂类,以及加组件定义;执行容器后处理器,然后同步配置信息;创建组件对象。该实施方式能够解决从字符串到程序类型转换出错,以及获取远程配置信息逻辑对业务侵入性高的问题。
The invention discloses a method and a device for realizing annotated configuration, and relates to the technical field of computers. A specific implementation of the method includes: reading a configuration file to implement environment settings; creating a component factory class, and adding component definitions; executing a container post-processor, and then synchronizing configuration information; and creating a component object. This embodiment can solve the problem that the conversion from the string to the program type is wrong, and the logic of acquiring the remote configuration information is highly intrusive to the business.
Description
技术领域technical field
本发明涉及计算机技术领域,尤其涉及一种实现注解式配置的方法和装置。The present invention relates to the field of computer technology, and in particular, to a method and apparatus for implementing annotated configuration.
背景技术Background technique
目前,绝大部分应用系统都需要一些配置信息。比如业务逻辑阈值的设置(一天允许单个用户下的单量)、一些开关的设置(是否走风控逻辑)。这类信息通常会存储到zookeeper(分布式的,开放源码的分布式应用程序协调服务)或自己实现的配置服务中心,采用被动通知或主动轮询的方式获取远程的值(都是字符串的形式),再转换为程序需要的数据类型(Integer、Boolean、Date等)然后缓存到本地(比如:JVM中某个静态变量中)。At present, most application systems require some configuration information. For example, the setting of the business logic threshold (allowing a single user to place orders in one day), and the setting of some switches (whether to follow the risk control logic). This kind of information is usually stored in zookeeper (distributed, open source distributed application coordination service) or self-implemented configuration service center, and passive notification or active polling is used to obtain remote values (both are strings). form), and then converted to the data type required by the program (Integer, Boolean, Date, etc.) and then cached locally (for example: a static variable in the JVM).
在实现本发明过程中,发明人发现现有技术中至少存在如下问题:In the process of realizing the present invention, the inventor found that there are at least the following problems in the prior art:
从“字符串”到“程序类型”的转换并且缓存到本地,这个处理过程,分散在应用需要配置信息的各个地方,对应用程序的业务逻辑具有一定的侵入性,而且如果和远程同步不当,还会影响正常的业务逻辑执行。The conversion from "string" to "program type" and cached locally, this processing process is scattered in various places where the application needs configuration information, which is intrusive to the application's business logic, and if it is not synchronized with the remote, It will also affect normal business logic execution.
发明内容SUMMARY OF THE INVENTION
有鉴于此,本发明实施例提供一种实现注解式配置的方法和装置,能够解决从字符串到程序类型转换出错,以及获取远程配置信息逻辑对业务侵入性高的问题。In view of this, the embodiments of the present invention provide a method and apparatus for implementing annotated configuration, which can solve the problems of conversion errors from strings to program types and the high intrusiveness of business logic for obtaining remote configuration information.
为实现上述目的,根据本发明实施例的一个方面,提供了一种实现注解式配置的方法,包括读取配置文件,以实现环境设置;创建组件工厂类,以及加组件定义;执行容器后处理器,然后同步配置信息;创建组件对象。In order to achieve the above object, according to an aspect of the embodiments of the present invention, a method for implementing annotated configuration is provided, including reading a configuration file to implement environment settings; creating a component factory class, and adding component definitions; performing container post-processing , then synchronize the configuration information; create a component object.
可选地,执行容器后处理器,然后同步配置信息,包括:Optionally, execute the container post-processor, and then synchronize configuration information, including:
解析@ConfigPath和@ConfigKey,以获得@ConfigPath和@ConfigKey分别对应的Key值、Value值;Parse @ConfigPath and @ConfigKey to obtain the Key value and Value value corresponding to @ConfigPath and @ConfigKey respectively;
连接远程配置中心,判断是否存在@ConfigPath和@ConfigKey分别对应的Key值、Value值;Connect to the remote configuration center to determine whether there are Key values and Value values corresponding to @ConfigPath and @ConfigKey respectively;
如果存在,则获取远程配置中心的@ConfigPath的Key值、Value值,和@ConfigKey的Key值和Value值,以更新至本地;If it exists, obtain the Key value and Value value of @ConfigPath of the remote configuration center, and the Key value and Value value of @ConfigKey to update it locally;
如果不存在,则在远程配置中心添加解析后的@ConfigPath的Key值、Value值,和@ConfigKey的Key值和Value值。If it does not exist, add the parsed Key value and Value value of @ConfigPath, and the Key value and Value value of @ConfigKey in the remote configuration center.
可选地,对解析后的@ConfigPath的Key值、Value值,和解析后的@ConfigKey的Key值和Value值添加注解。Optionally, add annotations to the Key value and Value value of the parsed @ConfigPath, and the Key value and Value value of the parsed @ConfigKey.
可选地,获取远程配置中心的@ConfigPath的Key值、Value值,和@ConfigKey的Key值和Value值之前,包括:Optionally, before obtaining the Key value and Value value of @ConfigPath of the remote configuration center, and the Key value and Value value of @ConfigKey, include:
通过Spring框架的PropertyEditor把配置信息的字符串形式转换为Key对应数据类型的值;其中,配置信息为远程配置中心的@ConfigPath的Key值、Value值,和@ConfigKey的Key值和Value值。The string form of the configuration information is converted into the value of the data type corresponding to the Key through the PropertyEditor of the Spring framework; the configuration information is the Key value and Value value of @ConfigPath of the remote configuration center, and the Key value and Value value of @ConfigKey.
另外,根据本发明实施例的一个方面,提供了一种实现注解式配置的装置,包括设置模块,用于读取配置文件,以实现环境设置;创建组件工厂类,以及加载组件定义;配置模块,用于执行容器后处理器,然后同步配置信息,进而创建组件对象。In addition, according to an aspect of the embodiments of the present invention, an apparatus for implementing annotated configuration is provided, including a setting module for reading a configuration file to implement environment setting; creating a component factory class, and loading a component definition; a configuration module , which is used to execute the container post-processor, then synchronize the configuration information, and then create the component object.
可选地,所述配置模块执行容器后处理器,然后同步配置信息,包括:Optionally, the configuration module executes the container post-processor, and then synchronizes configuration information, including:
解析@ConfigPath和@ConfigKey,以获得@ConfigPath和@ConfigKey分别对应的Key值、Value值;Parse @ConfigPath and @ConfigKey to obtain the Key value and Value value corresponding to @ConfigPath and @ConfigKey respectively;
连接远程配置中心,判断是否存在@ConfigPath和@ConfigKey分别对应的Key值、Value值;Connect to the remote configuration center to determine whether there are Key values and Value values corresponding to @ConfigPath and @ConfigKey respectively;
如果存在,则获取远程配置中心的@ConfigPath的Key值、Value值,和@ConfigKey的Key值和Value值,以更新至本地;If it exists, obtain the Key value and Value value of @ConfigPath of the remote configuration center, and the Key value and Value value of @ConfigKey to update it locally;
如果不存在,则在远程配置中心添加解析后的@ConfigPath的Key值、Value值,和@ConfigKey的Key值和Value值。If it does not exist, add the parsed Key value and Value value of @ConfigPath, and the Key value and Value value of @ConfigKey in the remote configuration center.
可选地,所述配置模块,还用于:Optionally, the configuration module is also used for:
对解析后的@ConfigPath的Key值、Value值,和解析后的@ConfigKey的Key值和Value值添加注解。Add annotations to the Key value and Value value of the parsed @ConfigPath, and the Key value and Value value of the parsed @ConfigKey.
可选地,所述配置模块获取远程配置中心的@ConfigPath的Key值、Value值,和@ConfigKey的Key值和Value值之前,包括:Optionally, before the configuration module obtains the Key value and Value value of @ConfigPath of the remote configuration center, and the Key value and Value value of @ConfigKey, it includes:
通过Spring框架的PropertyEditor把配置信息的字符串形式转换为Key对应数据类型的值;其中,配置信息为远程配置中心的@ConfigPath的Key值、Value值,和@ConfigKey的Key值和Value值。The string form of the configuration information is converted into the value of the data type corresponding to the Key through the PropertyEditor of the Spring framework; the configuration information is the Key value and Value value of @ConfigPath of the remote configuration center, and the Key value and Value value of @ConfigKey.
根据本发明实施例的另一个方面,还提供了一种电子设备,包括:According to another aspect of the embodiments of the present invention, an electronic device is also provided, including:
一个或多个处理器;one or more processors;
存储装置,用于存储一个或多个程序,storage means for storing one or more programs,
当所述一个或多个程序被所述一个或多个处理器执行,使得所述一个或多个处理器实现上述任一实现注解式配置的实施例所述的方法。When the one or more programs are executed by the one or more processors, the one or more processors cause the one or more processors to implement the method described in any of the foregoing embodiments for implementing annotated configuration.
根据本发明实施例的另一个方面,还提供了一种计算机可读介质,其上存储有计算机程序,所述程序被处理器执行时实现上述任一基于实现注解式配置的实施例所述的方法。According to another aspect of the embodiments of the present invention, a computer-readable medium is also provided, on which a computer program is stored, and when the program is executed by a processor, implements any of the foregoing embodiments based on implementing annotated configuration. method.
上述发明中的一个实施例具有如下优点或有益效果:本发明通过注解式配置结合Spring(开放源代码的设计层面框架,解决的是业务逻辑层和其他各层的松耦合问题)特性,实现了一个对业务低侵入的配置信息同步客户端,从而做到了配置信息和类型的自动转换,同时统一配置信息的处理逻辑,而且对应用是透明低侵入的。An embodiment of the above invention has the following advantages or beneficial effects: the present invention combines Spring (an open source design level framework, which solves the problem of loose coupling between the business logic layer and other layers) characteristics through annotation configuration, and realizes the A configuration information synchronization client with low business intrusion, so as to achieve automatic conversion of configuration information and types, and at the same time unify the processing logic of configuration information, and it is transparent and low intrusion to applications.
上述的非惯用的可选方式所具有的进一步效果将在下文中结合具体实施方式加以说明。Further effects of the above non-conventional alternatives will be described below in conjunction with specific embodiments.
附图说明Description of drawings
附图用于更好地理解本发明,不构成对本发明的不当限定。其中:The accompanying drawings are used for better understanding of the present invention and do not constitute an improper limitation of the present invention. in:
图1是根据本发明实施例的实现注解式配置的方法的主要流程的示意图;1 is a schematic diagram of a main flow of a method for implementing annotated configuration according to an embodiment of the present invention;
图2是根据本发明可参考实施例的实现注解式配置的方法的主要流程的示意图;2 is a schematic diagram of the main flow of a method for implementing annotated configuration according to a referenced embodiment of the present invention;
图3是根据本发明实施例的实现注解式配置的装置的主要模块的示意图;3 is a schematic diagram of main modules of an apparatus for implementing annotated configuration according to an embodiment of the present invention;
图4是本发明实施例可以应用于其中的示例性系统架构图;4 is an exemplary system architecture diagram to which an embodiment of the present invention may be applied;
图5是适于用来实现本发明实施例的终端设备或服务器的计算机系统的结构示意图。FIG. 5 is a schematic structural diagram of a computer system suitable for implementing a terminal device or a server according to an embodiment of the present invention.
具体实施方式Detailed ways
以下结合附图对本发明的示范性实施例做出说明,其中包括本发明实施例的各种细节以助于理解,应当将它们认为仅仅是示范性的。因此,本领域普通技术人员应当认识到,可以对这里描述的实施例做出各种改变和修改,而不会背离本发明的范围和精神。同样,为了清楚和简明,以下的描述中省略了对公知功能和结构的描述。Exemplary embodiments of the present invention are described below with reference to the accompanying drawings, which include various details of the embodiments of the present invention to facilitate understanding and should be considered as exemplary only. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted from the following description for clarity and conciseness.
图1是根据本发明实施例的实现注解式配置的方法的主要流程的示意图,所述实现注解式配置的方法可以包括:FIG. 1 is a schematic diagram of a main process of a method for implementing annotated configuration according to an embodiment of the present invention. The method for implementing annotated configuration may include:
步骤S101,读取配置文件,以实现环境设置。Step S101, read the configuration file to realize environment setting.
步骤S102,创建组件工厂类,以及加载组件定义。In step S102, a component factory class is created, and a component definition is loaded.
较佳地,在本发明中采用的组件是Bean,而组件工厂类则为BeanFactory。进一步地,可以创建BeanFactory,以及加载Bean定义。Preferably, the component used in the present invention is Bean, and the component factory class is BeanFactory. Further, BeanFactory can be created, and bean definitions can be loaded.
步骤S103,执行容器后处理器,然后同步配置信息,进而创建组件对象。Step S103: Execute the container post-processor, then synchronize the configuration information, and then create a component object.
较佳地,如果采用的组件是Bean,则执行容器后处理器,然后同步配置信息,进而创建Bean对象。Preferably, if the adopted component is a Bean, the container post-processor is executed, and then the configuration information is synchronized to create the Bean object.
在进一步地实施例中,在执行容器后处理器,然后同步配置信息时,可以通过如下过程进行:In a further embodiment, when the container post-processor is executed and then the configuration information is synchronized, the following process may be used:
解析@ConfigPath和@ConfigKey,以获得@ConfigPath和@ConfigKey分别对应的Key值、Value值。Parse @ConfigPath and @ConfigKey to obtain the Key value and Value value corresponding to @ConfigPath and @ConfigKey respectively.
连接远程配置中心,判断是否存在@ConfigPath和@ConfigKey分别对应的Key值、Value值。Connect to the remote configuration center to determine whether there are Key and Value values corresponding to @ConfigPath and @ConfigKey respectively.
根据判断结果,如果存在则获取远程配置中心的@ConfigPath的Key值、Value值,和@ConfigKey的Key值和Value值,以更新至本地。如果不存在,则在远程配置中心添加解析后的@ConfigPath的Key值、Value值,和@ConfigKey的Key值和Value值。According to the judgment result, if it exists, obtain the Key value and Value value of @ConfigPath of the remote configuration center, and the Key value and Value value of @ConfigKey to update it locally. If it does not exist, add the parsed Key value and Value value of @ConfigPath, and the Key value and Value value of @ConfigKey in the remote configuration center.
在更进一步地实施例中,可以对解析后的@ConfigPath的Key值、Value值,和解析后的@ConfigKey的Key值和Value值添加注解。In a further embodiment, annotations may be added to the parsed Key value and Value value of @ConfigPath, and the parsed Key value and Value value of @ConfigKey.
还值得说明的是,在将远程配置中心的配置信息(即远程配置中心的@ConfigPath的Key值、Value值,和@ConfigKey的Key值和Value值。)更新至本地之前,可以通过Spring框架的PropertyEditor把配置信息的字符串形式转换为Key对应数据类型的值。It is also worth noting that, before updating the configuration information of the remote configuration center (that is, the Key value and Value value of @ConfigPath of the remote configuration center, and the Key value and Value value of @ConfigKey.) The PropertyEditor converts the string form of the configuration information into the value of the data type corresponding to the Key.
作为本发明另一个可参考的实施例,如图2所示,本实施例基于Spring的特性实现注解式配置,所述实现注解式配置的方法可以包括:As another referenced embodiment of the present invention, as shown in FIG. 2 , this embodiment implements annotated configuration based on characteristics of Spring, and the method for implementing annotated configuration may include:
步骤S201,解析property sources和profiles,以完成环境设置。Step S201, parse property sources and profiles to complete environment setting.
其中,通过解析property sources和profiles可以读取配置文件。Among them, the configuration file can be read by parsing property sources and profiles.
步骤S202,创建组件工厂类,以构建容器。Step S202, creating a component factory class to build a container.
例如,通过创建BeanFactory(Bean工厂类)可以获得IOC(Inversion of Control)容器。其中,所述的IOC(Inversion of Control)为控制反转,是一个削减程序耦合的法则。For example, an IOC (Inversion of Control) container can be obtained by creating a BeanFactory (Bean Factory Class). Among them, the IOC (Inversion of Control) is inversion of control, which is a law to reduce program coupling.
步骤S203,加载组件定义。Step S203, load the component definition.
其中,组件定义例如:Bean定义(即BeanDefinition)用来描述一个Bean的实例,包括:属性、构造函数及参数等其它一些Bean相关的信息。Among them, the component definition, such as: Bean definition (ie BeanDefinition) is used to describe an instance of a Bean, including: attributes, constructors, parameters and other Bean-related information.
步骤S204,执行容器后处理器,同步配置信息,以使本地与远程配置中心的配置信息一致。In step S204, the container post-processor is executed to synchronize the configuration information, so that the configuration information of the local and remote configuration centers is consistent.
在实施例中,在执行容器后处理器之后进行配置信息的同步,可以保证执行业务逻辑的时候,配置信息处于最新的状态,完美的使配置信息的同步和业务逻辑之间解耦,同时保证与远程配置中心的配置信息同步。其具体的实施过程包括:In the embodiment, the synchronization of the configuration information is performed after the container post-processor is executed, which can ensure that the configuration information is in the latest state when executing the business logic, which perfectly decouples the synchronization of the configuration information from the business logic, while ensuring that Synchronize with the configuration information of the remote configuration center. Its specific implementation process includes:
步骤一:解析@ConfigPath和@ConfigKey,以获得@ConfigPath的Key值、Value值,和@ConfigKey的Key值和Value值。Step 1: Parse @ConfigPath and @ConfigKey to obtain the Key value and Value value of @ConfigPath, and the Key value and Value value of @ConfigKey.
步骤二:连接远程配置中心,判断是否存在解析后@ConfigPath的Key值、Value值和解析后@ConfigKey的Key值、Value值,若存在则执行步骤三,否则执行步骤四。Step 2: Connect to the remote configuration center to determine whether there are the parsed Key value and Value value of @ConfigPath and the parsed @ConfigKey Key value and Value value. If so, go to Step 3, otherwise go to Step 4.
步骤三:获取远程配置中心的@ConfigPath的Key值、Value值,和@ConfigKey的Key值和Value值,以更新至本地。Step 3: Obtain the Key value and Value value of @ConfigPath in the remote configuration center, and the Key value and Value value of @ConfigKey to update it locally.
优选地,在获取到远程配置中心的配置信息后,可以通过Spring框架(是一个开放源代码的设计层面框架)的PropertyEditor(用于完成数据类型和字符串之间的转换)把配置信息的字符串形式转换为Key对应数据类型的值。其中,所述的配置信息就是远程配置中心的@ConfigPath的Key值、Value值,和@ConfigKey的Key值和Value值。Preferably, after obtaining the configuration information of the remote configuration center, the characters of the configuration information can be converted to the Character Editor of the Spring framework (which is an open-source design-level framework) (used to complete the conversion between data types and strings). The string form is converted to the value of the corresponding data type of Key. The configuration information is the Key value and Value value of @ConfigPath of the remote configuration center, and the Key value and Value value of @ConfigKey.
步骤四:在远程配置中心添加解析后的@ConfigPath的Key值、Value值,和@ConfigKey的Key值和Value值。Step 4: Add the parsed Key value and Value value of @ConfigPath, and the Key value and Value value of @ConfigKey in the remote configuration center.
值得说明的是,无论在执行完步骤三还是执行完步骤四之后都可以对远程配置中心进行监听,以监控@ConfigPath的Key值、Value值,和监控@ConfigKey的Key值和Value值。It is worth noting that no matter after step 3 or step 4 is performed, the remote configuration center can be monitored to monitor the Key value and Value value of @ConfigPath, and monitor the Key value and Value value of @ConfigKey.
步骤S205,创建组件对象,其默认为单例。Step S205, create a component object, which is a singleton by default.
例如,组件为Bean时可以调用Bean的构造函数,创建Bean实例,以创建Bean对象。For example, when the component is a Bean, the constructor of the Bean can be called to create a Bean instance to create a Bean object.
需要说明的是,在本发明中因为配置信息都是static的,所以在需要引用配置信息的时候,可以直接用(即可访问到):It should be noted that in the present invention, because the configuration information is static, when the configuration information needs to be referenced, it can be used directly (that is, it can be accessed):
类名.属性名classname.propertyname
作为本发明的进一步实施例,对@ConfigPath的Key值、Value值,和@ConfigKey的Key值和Value值添加注解,从而也可以实现了对业务较低的侵入性,即和传统配置信息同步方式相比,通过把配置信息同步的逻辑封装到注解和容器后处理中从而达到了和业务逻辑解耦的目的。As a further embodiment of the present invention, annotations are added to the Key value and Value value of @ConfigPath, and the Key value and Value value of @ConfigKey, so as to achieve less intrusiveness to the business, that is, to synchronize with traditional configuration information. In contrast, the purpose of decoupling from business logic is achieved by encapsulating the logic of configuration information synchronization into annotations and container post-processing.
其中,@ConfigPath可以表示这个类是个配置类,对应远程配置中心中的一个路径,例如:value=“/yanglikun”,即配置Path。另外,@ConfigPath有对应的读写权限值,同时支持spring占位符的方式根据profile加载不同运行环境下的秘钥。例如:readToken=“${ucc.yanglikun.readToken}”,即读秘钥。writeToken=“${ucc.yanglikun.writeToken}”,即写秘钥。Among them, @ConfigPath can indicate that this class is a configuration class, corresponding to a path in the remote configuration center, for example: value="/yanglikun", that is, the configuration Path. In addition, @ConfigPath has corresponding read and write permission values, and supports spring placeholders to load secret keys in different operating environments according to profiles. For example: readToken="${ucc.yanglikun.readToken}", that is, the read key. writeToken="${ucc.yanglikun.writeToken}", that is, write the secret key.
其中,@ConfigKey可以表示具体的配置信息(Key,Value),默认字段名就是远程配置中心的Key,当然也可以自定义,例如:@ConfigKey(“custom_key_name”),即指定字段值,默认字段名。Among them, @ConfigKey can represent specific configuration information (Key, Value), the default field name is the Key of the remote configuration center, of course, it can also be customized, for example: @ConfigKey("custom_key_name"), that is, the specified field value, the default field name .
图3是根据本发明实施例的实现注解式配置的装置,如图3所示,所述实现注解式配置的装置300包括设置模块301和配置模块302。其中,设置模块301读取配置文件,以实现环境设置;创建组件工厂类,以及加载组件定义。之后,配置模块302执行容器后处理器,然后同步配置信息,进而创建组件对象。FIG. 3 is an apparatus for implementing annotated configuration according to an embodiment of the present invention. As shown in FIG. 3 , the
作为进一步地实施例,所述配置模块302执行容器后处理器,然后同步配置信息的具体实施过程包括:As a further embodiment, the
解析@ConfigPath和@ConfigKey,以获得@ConfigPath和@ConfigKey分别对应的Key值、Value值。Parse @ConfigPath and @ConfigKey to obtain the Key value and Value value corresponding to @ConfigPath and @ConfigKey respectively.
连接远程配置中心,判断是否存在@ConfigPath和@ConfigKey分别对应的Key值、Value值。根据判断结果,如果存在,则获取远程配置中心的@ConfigPath的Key值、Value值,和@ConfigKey的Key值和Value值,以更新至本地。如果不存在,则在远程配置中心添加解析后的@ConfigPath的Key值、Value值,和@ConfigKey的Key值和Value值。Connect to the remote configuration center to determine whether there are Key and Value values corresponding to @ConfigPath and @ConfigKey respectively. According to the judgment result, if it exists, obtain the Key value and Value value of @ConfigPath of the remote configuration center, and the Key value and Value value of @ConfigKey to update it locally. If it does not exist, add the parsed Key value and Value value of @ConfigPath, and the Key value and Value value of @ConfigKey in the remote configuration center.
较佳地实施例,对解析后的@ConfigPath的Key值、Value值,和解析后的@ConfigKey的Key值和Value值添加注解。In a preferred embodiment, annotations are added to the parsed Key value and Value value of @ConfigPath, and the parsed Key value and Value value of @ConfigKey.
还值得说明的是,在获取远程配置中心的@ConfigPath的Key值、Value值,和@ConfigKey的Key值和Value值之前,通过Spring框架的PropertyEditor把配置信息的字符串形式转换为Key对应数据类型的值。其中,配置信息为远程配置中心的@ConfigPath的Key值、Value值,和@ConfigKey的Key值和Value值。It is also worth noting that, before obtaining the Key value and Value value of @ConfigPath of the remote configuration center, and the Key value and Value value of @ConfigKey, the String form of the configuration information is converted into the data type corresponding to the Key through the PropertyEditor of the Spring framework. value of . The configuration information is the Key value and Value value of @ConfigPath of the remote configuration center, and the Key value and Value value of @ConfigKey.
需要说明的是,在本发明所述实现注解式配置的装置的具体实施内容,在上面所述实现注解式配置的方法中已经详细说明了,故在此重复内容不再说明。It should be noted that, the specific implementation content of the apparatus for implementing annotated configuration according to the present invention has been described in detail in the method for implementing annotated configuration described above, so the repeated content will not be described here.
图4示出了可以应用本发明实施例的实现注解式配置的方法或实现注解式配置的装置的示例性系统架构400。FIG. 4 shows an
如图4所示,系统架构400可以包括终端设备401、402、403,网络404和服务器405。网络404用以在终端设备401、402、403和服务器405之间提供通信链路的介质。网络404可以包括各种连接类型,例如有线、无线通信链路或者光纤电缆等等。As shown in FIG. 4 , the
用户可以使用终端设备401、402、403通过网络404与服务器405交互,以接收或发送消息等。终端设备401、402、403上可以安装有各种通讯客户端应用,例如购物类应用、网页浏览器应用、搜索类应用、即时通信工具、邮箱客户端、社交平台软件等(仅为示例)。The user can use the
终端设备401、402、403可以是具有显示屏并且支持网页浏览的各种电子设备,包括但不限于智能手机、平板电脑、膝上型便携计算机和台式计算机等等。The
服务器405可以是提供各种服务的服务器,例如对用户利用终端设备401、402、403所浏览的购物类网站提供支持的后台管理服务器(仅为示例)。后台管理服务器可以对接收到的产品信息查询请求等数据进行分析等处理,并将处理结果(例如目标推送信息、产品信息--仅为示例)反馈给终端设备。The
需要说明的是,本发明实施例所提供的实现注解式配置的方法一般由服务器405执行,相应地,实现注解式配置的装置一般设置于服务器405中。It should be noted that the method for implementing annotated configuration provided by the embodiment of the present invention is generally performed by the
应该理解,图4中的终端设备、网络和服务器的数目仅仅是示意性的。根据实现需要,可以具有任意数目的终端设备、网络和服务器。It should be understood that the numbers of terminal devices, networks and servers in FIG. 4 are merely illustrative. There can be any number of terminal devices, networks and servers according to implementation needs.
下面参考图5,其示出了适于用来实现本发明实施例的终端设备的计算机系统500的结构示意图。图5示出的终端设备仅仅是一个示例,不应对本发明实施例的功能和使用范围带来任何限制。Referring to FIG. 5 below, it shows a schematic structural diagram of a
如图5所示,计算机系统500包括中央处理单元(CPU)501,其可以根据存储在只读存储器(ROM)502中的程序或者从存储部分508加载到随机访问存储器(RAM)503中的程序而执行各种适当的动作和处理。在RAM503中,还存储有系统500操作所需的各种程序和数据。CPU501、ROM 502以及RAM503通过总线504彼此相连。输入/输出(I/O)接口505也连接至总线504。As shown in FIG. 5, a
以下部件连接至I/O接口505:包括键盘、鼠标等的输入部分506;包括诸如阴极射线管(CRT)、液晶显示器(LCD)等以及扬声器等的输出部分507;包括硬盘等的存储部分508;以及包括诸如LAN卡、调制解调器等的网络接口卡的通信部分509。通信部分509经由诸如因特网的网络执行通信处理。驱动器510也根据需要连接至I/O接口505。可拆卸介质511,诸如磁盘、光盘、磁光盘、半导体存储器等等,根据需要安装在驱动器510上,以便于从其上读出的计算机程序根据需要被安装入存储部分508。The following components are connected to the I/O interface 505: an
特别地,根据本发明公开的实施例,上文参考流程图描述的过程可以被实现为计算机软件程序。例如,本发明公开的实施例包括一种计算机程序产品,其包括承载在计算机可读介质上的计算机程序,该计算机程序包含用于执行流程图所示的方法的程序代码。在这样的实施例中,该计算机程序可以通过通信部分509从网络上被下载和安装,和/或从可拆卸介质511被安装。在该计算机程序被中央处理单元(CPU)501执行时,执行本发明的系统中限定的上述功能。In particular, the processes described above with reference to the flowcharts may be implemented as computer software programs in accordance with the disclosed embodiments of the present invention. For example, embodiments disclosed herein include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the method illustrated in the flowchart. In such an embodiment, the computer program may be downloaded and installed from the network via the
需要说明的是,本发明所示的计算机可读介质可以是计算机可读信号介质或者计算机可读存储介质或者是上述两者的任意组合。计算机可读存储介质例如可以是——但不限于——电、磁、光、电磁、红外线、或半导体的系统、装置或器件,或者任意以上的组合。计算机可读存储介质的更具体的例子可以包括但不限于:具有一个或多个导线的电连接、便携式计算机磁盘、硬盘、随机访问存储器(RAM)、只读存储器(ROM)、可擦式可编程只读存储器(EPROM或闪存)、光纤、便携式紧凑磁盘只读存储器(CD-ROM)、光存储器件、磁存储器件、或者上述的任意合适的组合。在本发明中,计算机可读存储介质可以是任何包含或存储程序的有形介质,该程序可以被指令执行系统、装置或者器件使用或者与其结合使用。而在本发明中,计算机可读的信号介质可以包括在基带中或者作为载波一部分传播的数据信号,其中承载了计算机可读的程序代码。这种传播的数据信号可以采用多种形式,包括但不限于电磁信号、光信号或上述的任意合适的组合。计算机可读的信号介质还可以是计算机可读存储介质以外的任何计算机可读介质,该计算机可读介质可以发送、传播或者传输用于由指令执行系统、装置或者器件使用或者与其结合使用的程序。计算机可读介质上包含的程序代码可以用任何适当的介质传输,包括但不限于:无线、电线、光缆、RF等等,或者上述的任意合适的组合。It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium, or any combination of the above two. The computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus or device, or a combination of any of the above. More specific examples of computer readable storage media may include, but are not limited to, electrical connections with one or more wires, portable computer disks, hard disks, random access memory (RAM), read only memory (ROM), erasable Programmable read only memory (EPROM or flash memory), fiber optics, portable compact disk read only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing. In the present invention, a computer-readable storage medium may be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In the present invention, however, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code therein. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the foregoing. A computer-readable signal medium can also be any computer-readable medium other than a computer-readable storage medium that can transmit, propagate, or transport the program for use by or in connection with the instruction execution system, apparatus, or device . Program code embodied on a computer readable medium may be transmitted using any suitable medium including, but not limited to, wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
附图中的流程图和框图,图示了按照本发明各种实施例的系统、方法和计算机程序产品的可能实现的体系架构、功能和操作。在这点上,流程图或框图中的每个方框可以代表一个模块、程序段、或代码的一部分,上述模块、程序段、或代码的一部分包含一个或多个用于实现规定的逻辑功能的可执行指令。也应当注意,在有些作为替换的实现中,方框中所标注的功能也可以以不同于附图中所标注的顺序发生。例如,两个接连地表示的方框实际上可以基本并行地执行,它们有时也可以按相反的顺序执行,这依所涉及的功能而定。也要注意的是,框图或流程图中的每个方框、以及框图或流程图中的方框的组合,可以用执行规定的功能或操作的专用的基于硬件的系统来实现,或者可以用专用硬件与计算机指令的组合来实现。The flowchart and block diagrams in the Figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code that contains one or more logical functions for implementing the specified functions executable instructions. It should also be noted that, in some alternative implementations, the functions noted in the blocks may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It is also noted that each block of the block diagrams or flowchart illustrations, and combinations of blocks in the block diagrams or flowchart illustrations, can be implemented in special purpose hardware-based systems that perform the specified functions or operations, or can be implemented using A combination of dedicated hardware and computer instructions is implemented.
描述于本发明实施例中所涉及到的模块可以通过软件的方式实现,也可以通过硬件的方式来实现。所描述的模块也可以设置在处理器中,例如,可以描述为:一种处理器包括设置模块和配置模块。其中,这些模块的名称在某种情况下并不构成对该模块本身的限定。The modules involved in the embodiments of the present invention may be implemented in a software manner, and may also be implemented in a hardware manner. The described modules can also be provided in the processor, for example, it can be described as: a processor includes a setting module and a configuration module. Among them, the names of these modules do not constitute a limitation on the module itself under certain circumstances.
作为另一方面,本发明还提供了一种计算机可读介质,该计算机可读介质可以是上述实施例中描述的设备中所包含的;也可以是单独存在,而未装配入该设备中。上述计算机可读介质承载有一个或者多个程序,当上述一个或者多个程序被一个该设备执行时,使得该设备包括:读取配置文件,以实现环境设置;读取配置文件,以实现环境设置;创建组件工厂类,以及加组件定义;执行容器后处理器,然后同步配置信息;创建组件对象。As another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiments; or may exist alone without being assembled into the device. The above-mentioned computer-readable medium carries one or more programs, and when the above-mentioned one or more programs are executed by a device, the device includes: reading a configuration file to realize the environment setting; reading the configuration file to realize the environment Set up; create a component factory class, and add component definitions; execute the container post-processor, and then synchronize configuration information; create a component object.
根据本发明实施例的技术方案,能够解决从字符串到程序类型转换出错,以及获取远程配置信息逻辑对业务侵入性高的问题。According to the technical solutions of the embodiments of the present invention, it is possible to solve the problems of errors in converting from character strings to program types, and the high intrusiveness of the logic of acquiring remote configuration information to services.
上述具体实施方式,并不构成对本发明保护范围的限制。本领域技术人员应该明白的是,取决于设计要求和其他因素,可以发生各种各样的修改、组合、子组合和替代。任何在本发明的精神和原则之内所作的修改、等同替换和改进等,均应包含在本发明保护范围之内。The above-mentioned specific embodiments do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modifications, equivalent replacements and improvements made within the spirit and principle of the present invention shall be included within the protection scope of the present invention.
Claims (10)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201810863084.XA CN110795135B (en) | 2018-08-01 | 2018-08-01 | A method and device for implementing annotation configuration |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201810863084.XA CN110795135B (en) | 2018-08-01 | 2018-08-01 | A method and device for implementing annotation configuration |
Publications (2)
Publication Number | Publication Date |
---|---|
CN110795135A true CN110795135A (en) | 2020-02-14 |
CN110795135B CN110795135B (en) | 2025-02-21 |
Family
ID=69425896
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201810863084.XA Active CN110795135B (en) | 2018-08-01 | 2018-08-01 | A method and device for implementing annotation configuration |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN110795135B (en) |
Cited By (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN112835650A (en) * | 2021-03-18 | 2021-05-25 | 南威软件股份有限公司 | Method and system for realizing system parameter unified configuration real-time effect |
CN112905167A (en) * | 2021-03-11 | 2021-06-04 | 北京字节跳动网络技术有限公司 | Application operation method and device and electronic equipment |
CN113608819A (en) * | 2021-06-18 | 2021-11-05 | 北京汇钧科技有限公司 | Method and device for creating container, electronic equipment and medium |
CN114372103A (en) * | 2021-12-31 | 2022-04-19 | 深圳优美创新科技有限公司 | Multi-data source processing method, device, system and storage medium |
Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102541996A (en) * | 2011-11-22 | 2012-07-04 | 大唐软件技术股份有限公司 | JDBC (java database connectivity) based data access layer building method and device utilizing same |
US20140075561A1 (en) * | 2012-09-12 | 2014-03-13 | International Business Machines Corporation | Static security analysis using a hybrid representation of string values |
CN106681861A (en) * | 2016-12-08 | 2017-05-17 | 杭州销冠网络科技有限公司 | New environment isolation configuration data management method and system |
CN106990979A (en) * | 2017-01-22 | 2017-07-28 | 阿里巴巴集团控股有限公司 | A kind of configuration information update method, system, client and server |
CN108304251A (en) * | 2018-02-06 | 2018-07-20 | 网宿科技股份有限公司 | Thread synchronization method and server |
-
2018
- 2018-08-01 CN CN201810863084.XA patent/CN110795135B/en active Active
Patent Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102541996A (en) * | 2011-11-22 | 2012-07-04 | 大唐软件技术股份有限公司 | JDBC (java database connectivity) based data access layer building method and device utilizing same |
US20140075561A1 (en) * | 2012-09-12 | 2014-03-13 | International Business Machines Corporation | Static security analysis using a hybrid representation of string values |
CN106681861A (en) * | 2016-12-08 | 2017-05-17 | 杭州销冠网络科技有限公司 | New environment isolation configuration data management method and system |
CN106990979A (en) * | 2017-01-22 | 2017-07-28 | 阿里巴巴集团控股有限公司 | A kind of configuration information update method, system, client and server |
CN108304251A (en) * | 2018-02-06 | 2018-07-20 | 网宿科技股份有限公司 | Thread synchronization method and server |
Cited By (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN112905167A (en) * | 2021-03-11 | 2021-06-04 | 北京字节跳动网络技术有限公司 | Application operation method and device and electronic equipment |
CN112905167B (en) * | 2021-03-11 | 2023-10-27 | 北京字节跳动网络技术有限公司 | Application operation method and device and electronic equipment |
CN112835650A (en) * | 2021-03-18 | 2021-05-25 | 南威软件股份有限公司 | Method and system for realizing system parameter unified configuration real-time effect |
CN113608819A (en) * | 2021-06-18 | 2021-11-05 | 北京汇钧科技有限公司 | Method and device for creating container, electronic equipment and medium |
CN114372103A (en) * | 2021-12-31 | 2022-04-19 | 深圳优美创新科技有限公司 | Multi-data source processing method, device, system and storage medium |
Also Published As
Publication number | Publication date |
---|---|
CN110795135B (en) | 2025-02-21 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN110019350B (en) | Data query method and device based on configuration information | |
CN110765187A (en) | A data source routing management method and device | |
CN111144926B (en) | Service request processing method, device, system, electronic equipment and readable medium | |
CN109522751B (en) | Access right control method and device, electronic equipment and computer readable medium | |
CN110795135B (en) | A method and device for implementing annotation configuration | |
CN110795315A (en) | Method and apparatus for monitoring services | |
CN111427701A (en) | Workflow engine system and business processing method | |
CN110209662A (en) | A kind of method and apparatus of automation load data | |
CN112948138A (en) | Method and device for processing message | |
CN110928571A (en) | Business program development method and device | |
CN110795328A (en) | Interface testing method and device | |
CN111831461A (en) | A method and apparatus for processing business processes | |
CN107957869A (en) | The fixed office cloud desktop system of one kind | |
US20240062855A1 (en) | Systems and methods for automated edit check generation in clinical trial datasets | |
CN110705935B (en) | Logistics document processing method and device | |
CN112783903B (en) | Method and device for generating update log | |
CN111984616A (en) | A method, device and system for updating shared files | |
CN112241332A (en) | Interface compensation method and device | |
CN111258572B (en) | Method and device for generating business code framework | |
US11216490B2 (en) | Method and system for the creation and maintenance of a web presence data store built automatically for all entities with a social media presence | |
CN112463616A (en) | Chaos testing method and device for Kubernetes container platform | |
CN112099841A (en) | Method and system for generating configuration file | |
CN112882741A (en) | Application management system and method | |
CN113760279A (en) | Method and device for generating page | |
CN112925795A (en) | Order data processing method and device |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |