CN103383646B - A kind of Groovy script loading method and device - Google Patents
A kind of Groovy script loading method and device Download PDFInfo
- Publication number
- CN103383646B CN103383646B CN201210135681.3A CN201210135681A CN103383646B CN 103383646 B CN103383646 B CN 103383646B CN 201210135681 A CN201210135681 A CN 201210135681A CN 103383646 B CN103383646 B CN 103383646B
- Authority
- CN
- China
- Prior art keywords
- script
- groovy script
- groovy
- spring
- javabean
- 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.)
- Expired - Fee Related
Links
Landscapes
- Devices For Executing Special Programs (AREA)
Abstract
本申请公开了一种Groovy脚本加载方法及装置,用以解决现有技术中Groovy脚本的可扩展性和使用的灵活性较低的问题。该方法读取Groovy脚本,获取该Groovy脚本的属性信息,生成对应的XML配置文件并加载至Spring上下文中,最后将该Groovy脚本作为JavaBean加载至Spring上下文中。由于在Spring框架下的多个JavaBean可以互相引用,因此将Groovy脚本作为JavaBean加载至Spring上下文中,Groovy脚本可以直接引用其他JavaBean,其他JavaBean也可以直接引用该Groovy脚本,从而提高了Groovy脚本的可扩展性和使用的灵活性。
The application discloses a Groovy script loading method and device, which are used to solve the problem of low scalability and use flexibility of the Groovy script in the prior art. This method reads the Groovy script, obtains the attribute information of the Groovy script, generates the corresponding XML configuration file and loads it into the Spring context, and finally loads the Groovy script into the Spring context as a JavaBean. Since multiple JavaBeans under the Spring framework can refer to each other, the Groovy script is loaded into the Spring context as a JavaBean. The Groovy script can directly refer to other JavaBean, and other JavaBean can also directly refer to the Groovy script, thereby improving the reliability of the Groovy script. Scalability and flexibility of use.
Description
技术领域 technical field
本申请涉及通信技术领域,尤其涉及一种Groovy脚本加载方法及装置。The present application relates to the technical field of communications, and in particular to a Groovy script loading method and device.
背景技术 Background technique
Groovy是一种新兴的Java2平台语言,由于其可以与Java代码很好的结合,可以用Groovy在Java平台上进行Java编程,因此Groovy被广泛的应用于各个领域。Groovy is an emerging Java2 platform language. Because it can be well combined with Java code, Groovy can be used for Java programming on the Java platform, so Groovy is widely used in various fields.
例如,当本地系统需要与至少一个外部系统交互时,由于各个外部系统所使用的报文的格式各不相同,而本地系统又不支持外部系统发送的报文的格式,因此就需要在本地系统和外部系统之间建立交互平台,由交互平台将外部系统所使用的报文的格式统一转换为本地系统支持的格式,再发送给本地系统解析。具体的,在该交互平台中设置格式转换功能模块,该格式转换功能模块就可以采用编写的Groovy脚本来进行报文格式的转换。For example, when the local system needs to interact with at least one external system, since the formats of the packets used by each external system are different, and the local system does not support the format of the packets sent by the external system, it is necessary to Establish an interactive platform with the external system, and the interactive platform will uniformly convert the format of the message used by the external system into a format supported by the local system, and then send it to the local system for analysis. Specifically, a format conversion function module is set in the interactive platform, and the format conversion function module can use the written Groovy script to convert the message format.
在现有技术中,采用Groovy脚本进行报文格式转换的过程具体为,格式转换功能模块通过Groovy类加载器(GroovyClassLoader)对编写的Groovy脚本进行编译,并在编译成功后,通过GroovyClassLoader加载该Groovy脚本,通过加载的Groovy脚本完成相应的功能。In the prior art, the process of using Groovy scripts for message format conversion is specifically, the format conversion function module compiles the written Groovy scripts through the Groovy ClassLoader (GroovyClassLoader), and after the compilation is successful, loads the Groovy scripts through the GroovyClassLoader Script, complete the corresponding function through the loaded Groovy script.
但是,采用上述方法加载Groovy脚本时,如果后续需要对该Groovy脚本的功能进行扩展,例如增加该交互平台中已有的其他功能模块的功能,就需要重新编写整个Groovy脚本,并再次加载至格式转换功能模块。而该交互平台的某个其他功能模块中的脚本如果也要增加该Groovy脚本的功能,则也需要重新编写该其他功能模块中的脚本并加载。因此,现有技术中Groovy脚本加载的方法降低了Groovy脚本的可扩展性,也降低了Groovy脚本使用的灵活性。However, when using the above method to load the Groovy script, if the function of the Groovy script needs to be expanded subsequently, such as adding the functions of other functional modules existing in the interactive platform, the entire Groovy script needs to be rewritten and loaded into the format again. Convert function modules. And if the script in some other functional module of the interactive platform also needs to increase the function of the Groovy script, the script in the other functional module also needs to be rewritten and loaded. Therefore, the Groovy script loading method in the prior art reduces the scalability of the Groovy script, and also reduces the flexibility of using the Groovy script.
发明内容 Contents of the invention
本申请实施例提供一种Groovy脚本加载方法及装置,用以解决现有技术中Groovy脚本的可扩展性和使用的灵活性较低的问题。The embodiments of the present application provide a Groovy script loading method and device, which are used to solve the problem of low scalability and use flexibility of the Groovy script in the prior art.
本申请实施例提供的一种Groovy脚本加载方法,包括:A Groovy script loading method provided in the embodiment of the present application includes:
Spring脚本加载器读取数据库中存储的Groovy脚本;并The Spring script loader reads Groovy scripts stored in the database; and
获取所述Groovy脚本的属性信息,根据获取的属性信息生成对应的可扩展标记语言XML配置文件,并加载至Sping上下文中;以及Obtain the attribute information of the Groovy script, generate a corresponding Extensible Markup Language XML configuration file according to the acquired attribute information, and load it into the Spring context; and
将所述Groovy脚本作为JavaBean加载至Spring上下文中,并将Spring上下文中加载的其他JavaBean提供给加载的所述Groovy脚本引用,或者将加载的所述Groovy脚本提供给Spring上下文中加载的其他JavaBean引用。Load the Groovy script as a JavaBean into the Spring context, and provide other JavaBean loaded in the Spring context to the loaded Groovy script reference, or provide the loaded Groovy script to other JavaBean references loaded in the Spring context .
本申请实施例提供的一种Groovy脚本加载装置,包括:A Groovy script loading device provided in an embodiment of the present application includes:
Groovy脚本缓存管理单元,用于读取数据库中存储的Groovy脚本;Groovy script cache management unit, used to read Groovy scripts stored in the database;
Spring可扩展标记语言XML配置组装单元,用于获取所述Groovy脚本的属性信息,根据获取的属性信息生成对应的XML配置文件,并加载至Spring上下文中;The Spring Extensible Markup Language XML configuration assembly unit is used to obtain the attribute information of the Groovy script, generate a corresponding XML configuration file according to the obtained attribute information, and load it into the Spring context;
Bean处理器Processor单元,用于将所述Groovy脚本作为JavaBean加载至Spring上下文中,并将Spring上下文中加载的其他JavaBean提供给加载的所述Groovy脚本引用,或者将加载的所述Groovy脚本提供给Spring上下文中加载的其他JavaBean引用。The Bean processor Processor unit is used to load the Groovy script into the Spring context as a JavaBean, and provide other JavaBean loaded in the Spring context to the loaded Groovy script reference, or provide the loaded Groovy script to Other JavaBean references loaded in the Spring context.
本申请实施例提供一种Groovy脚本加载方法及装置,该方法Spring脚本加载器读取数据库中存储的Groovy脚本,获取该Groovy脚本的属性信息,生成对应的XML配置文件并加载至Spring上下文中,最后将该Groovy脚本作为JavaBean加载至Spring上下文中。由于在Spring框架下的多个JavaBean可以根据需要互相引用,因此本申请实施例中将Groovy脚本作为一个JavaBean加载至Spring上下文中,可以使该Groovy脚本在需要扩展功能时,直接引用Spring上下文中的其他JavaBean,其他JavaBean在需要扩展该Groovy脚本的功能时,也可以直接引用同样作为JavaBean的该Groovy脚本,从而提高了Groovy脚本的可扩展性和使用的灵活性。The embodiment of the present application provides a Groovy script loading method and device, in which the Spring script loader reads the Groovy script stored in the database, obtains the attribute information of the Groovy script, generates a corresponding XML configuration file and loads it into the Spring context, Finally, the Groovy script is loaded into the Spring context as a JavaBean. Since multiple JavaBeans under the Spring framework can refer to each other as needed, the Groovy script is loaded into the Spring context as a JavaBean in the embodiment of this application, so that the Groovy script can directly refer to the Other JavaBean, when other JavaBean needs to extend the function of the Groovy script, can also directly refer to the Groovy script which is also a JavaBean, thereby improving the scalability and flexibility of the Groovy script.
附图说明 Description of drawings
图1为本申请实施例提供的Groovy脚本加载过程;Fig. 1 is the Groovy script loading process that the embodiment of the present application provides;
图2为本申请实施例提供的Groovy脚本加载的详细过程;Fig. 2 is the detailed process that the Groovy script loading that the embodiment of the present application provides;
图3为本申请实施例提供的Groovy脚本加载装置;Fig. 3 is the Groovy script loading device that the embodiment of the present application provides;
图4为本申请实施例提供的Spring脚本加载器具体实现结构示意图。FIG. 4 is a schematic diagram of a specific implementation structure of a Spring script loader provided in an embodiment of the present application.
具体实施方式 detailed description
由于Groovy语法和Java语法相似,因此本申请实施例中通过Spring脚本加载器将编写的Groovy脚本作为一个JavaBean加载到Spring上下文(SpringContext)中,而由于Spring上下文中的多个JavaBean均可以相互引用,因此该Groovy脚本可以直接引用Spring上下文中的其他JavaBean,其他JavaBean也可以引用同样作为JavaBean的该Groovy脚本,从而提高了Groovy脚本的可扩展性和使用的灵活性。Since the Groovy syntax is similar to the Java syntax, in the embodiment of this application, the Groovy script written as a JavaBean is loaded into the Spring context (SpringContext) through the Spring script loader, and since multiple JavaBean in the Spring context can refer to each other, Therefore, the Groovy script can directly refer to other JavaBeans in the Spring context, and other JavaBeans can also refer to the Groovy script that is also a JavaBean, thereby improving the scalability and flexibility of the Groovy script.
下面结合说明书附图,对本申请实施例进行详细描述。The embodiments of the present application will be described in detail below in conjunction with the accompanying drawings.
图1为本申请实施例提供的Groovy脚本加载过程,具体包括以下步骤:Fig. 1 is the Groovy script loading process that the embodiment of the present application provides, specifically comprises the following steps:
S101:Spring脚本加载器读取数据库中存储的Groovy脚本。S101: The Spring script loader reads the Groovy script stored in the database.
在本申请实施例中,可以将编写的Groovy脚本存储在数据库中,当然,也可以保存在其他存储器中。Spring脚本加载器中的Groovy脚本缓存管理单元读取该Groovy脚本,具体可以在该Spring脚本加载器所在的系统启动时读取数据库中存储的Groovy脚本,也可以定期读取Groovy脚本,还可以当数据库中的Groovy脚本发生变化时读取Groovy脚本,例如数据库中新增加了一个Groovy脚本,或者更新了一个Groovy脚本。In the embodiment of the present application, the written Groovy script can be stored in the database, of course, it can also be stored in other storages. The Groovy script cache management unit in the Spring script loader reads the Groovy script. Specifically, it can read the Groovy script stored in the database when the system where the Spring script loader is located starts, or periodically read the Groovy script. It can also be used as Read the Groovy script when the Groovy script in the database changes, for example, a new Groovy script is added to the database, or a Groovy script is updated.
S102:获取该Groovy脚本的属性信息,根据获取的属性信息生成对应的可扩展标记语言(ExtensibleMarkupLanguage,XML)配置文件,并加载至Spring上下文中。S102: Obtain attribute information of the Groovy script, generate a corresponding Extensible Markup Language (Extensible Markup Language, XML) configuration file according to the acquired attribute information, and load it into the Spring context.
由于将一个JavaBean加载至Spring上下文中时,首先要加载JavaBean的属性信息,包括该JavaBean的Bean标识或者类名称(ClassName)等属性信息,因此本申请实施例中Spring脚本加载器中的SpringXML配置组装单元获取该Groovy脚本的属性信息。由于将JavaBean的属性信息加载至Spring上下文中时需要通过XML配置文件进行加载,因此SpringXML配置组装单元根据获取的该Groovy脚本的属性信息生成对应的XML配置文件,并加载至Spring上下文中。Since when a JavaBean is loaded into the Spring context, the attribute information of the JavaBean must first be loaded, including attribute information such as the Bean ID or class name (ClassName) of the JavaBean, so the SpringXML configuration assembly in the Spring script loader in the embodiment of this application The unit acquires property information of the Groovy script. Since the attribute information of the JavaBean needs to be loaded through the XML configuration file when it is loaded into the Spring context, the SpringXML configuration assembly unit generates the corresponding XML configuration file according to the acquired attribute information of the Groovy script, and loads it into the Spring context.
例如,根据获取的Groovy脚本的ClassName,生成对应的XML配置文件如下:For example, according to the obtained ClassName of the Groovy script, the corresponding XML configuration file is generated as follows:
生成如上所述的XML配置文件后,SpringXML配置组装单元则可以把上述XML配置文件加载到Spring上下文中,其中,本申请实施例中的SpringXML配置组装单元可以为Spring的XmlBeanDefinitionReader。After generating the above XML configuration file, the SpringXML configuration assembly unit can load the above XML configuration file into the Spring context, wherein the SpringXML configuration assembly unit in the embodiment of this application can be Spring's XmlBeanDefinitionReader.
S103:将该Groovy脚本作为JavaBean加载至Spring上下文中。S103: Load the Groovy script into the Spring context as a JavaBean.
在本申请实施例中,在将该Groovy脚本的属性信息加载至Spring上下文中后,Spring脚本加载器中的Bean处理器(Processor)单元则可以将该Groovy脚本作为一个JavaBean加载至Spring上下文中,在需要扩展该Groovy脚本的功能时,则将Spring上下文中加载的其他JavaBean提供给加载的该Groovy脚本引用,在Spring上下文中的其他JavaBean需要扩展该Groovy脚本的功能时,则将加载的该Groovy脚本提供给Spring上下文中加载的其他JavaBean引用。In the embodiment of this application, after the attribute information of the Groovy script is loaded into the Spring context, the Bean processor (Processor) unit in the Spring script loader can load the Groovy script as a JavaBean into the Spring context, When the function of the Groovy script needs to be extended, other JavaBean loaded in the Spring context will be provided to the loaded Groovy script reference, and when other JavaBean in the Spring context needs to extend the function of the Groovy script, the Groovy script will be loaded The script provides references to other JavaBeans loaded in the Spring context.
该Spring上下文可以看成是一个Spring容器,容器中加载了多个JavaBean,每个JavaBean都可以完成相应的功能,而对于其中的一个JavaBean而言,该JavaBean可以引用容器中加载的其他一个或几个JavaBean,也可以被容器中加载的其他一个或几个JavaBean所引用,因此,本申请实施例中将Groovy脚本作为一个JavaBean加载至Spring上下文中,就可以通过引用其他加载的JavaBean的方式方便的扩展该Groovy脚本的功能,也可以使其他JavaBean灵活的引用该Groovy脚本,从而提高了Groovy脚本的可扩展性和使用的灵活性。The Spring context can be regarded as a Spring container, and multiple JavaBeans are loaded in the container, and each JavaBean can complete the corresponding function, and for one of the JavaBean, the JavaBean can refer to one or several other JavaBean loaded in the container. A JavaBean can also be referenced by one or several other JavaBean loaded in the container. Therefore, in the embodiment of this application, the Groovy script is loaded into the Spring context as a JavaBean, which can be conveniently referred to by other loaded JavaBean. Extending the function of the Groovy script can also enable other JavaBeans to flexibly refer to the Groovy script, thereby improving the scalability and flexibility of the Groovy script.
例如,该Groovy脚本的功能是将外部系统发送的报文的格式转换为本地系统支持的格式,如果要将该Groovy脚本的功能扩展为先对外部系统发送的报文进行解密,再对解密后的报文进行格式转换,则本申请实施例中将该Groovy脚本作为JavaBean加载至Spring上下文中后,就可以直接引用Spring上下文中加载的具有解密功能的另一个JavaBean,而无需重新编写整个Groovy脚本,从而提高了Groovy脚本的可扩展性。相应的,如果Spring上下文中加载的其他JavaBean要扩展报文格式转换功能时,也可以直接引用同样作为JavaBean的该Groovy脚本,从而提高了Groovy脚本使用的灵活性。For example, the function of the Groovy script is to convert the format of the message sent by the external system into a format supported by the local system. If the function of the Groovy script is to be extended to first decrypt the message sent by the external system, and then decrypt the format conversion of the message, then in the embodiment of the present application, after the Groovy script is loaded into the Spring context as a JavaBean, it can directly refer to another JavaBean with decryption function loaded in the Spring context, without rewriting the entire Groovy script , thus improving the scalability of Groovy scripts. Correspondingly, if other JavaBeans loaded in the Spring context want to extend the message format conversion function, they can also directly reference the Groovy script that is also a JavaBean, thereby improving the flexibility of using the Groovy script.
在本申请实施例中,为了尽量提高Groovy脚本的加载速度,在上述步骤S101中,当Spring脚本加载器读取数据库中存储的Groovy脚本时,将数据库中存储的该Groovy脚本读取到缓存中,从而在执行后续的步骤S102和S103时,生成并加载Groovy脚本的属性信息和加载Groovy脚本也都是在缓存中执行的,也即整个Spring上下文存在于缓存中。这样不仅可以提高Groovy脚本的加载速度,还可以在加载新脚本时,无需重启该Spring脚本加载器所在的整个系统,只需要刷新缓存即可。In the embodiment of the present application, in order to improve the loading speed of the Groovy script as much as possible, in the above step S101, when the Spring script loader reads the Groovy script stored in the database, the Groovy script stored in the database is read into the cache , so that when the subsequent steps S102 and S103 are executed, generating and loading the property information of the Groovy script and loading the Groovy script are also performed in the cache, that is, the entire Spring context exists in the cache. This can not only improve the loading speed of the Groovy script, but also save the need to restart the entire system where the Spring script loader is located when loading a new script, and only need to refresh the cache.
在本申请实施例中,为了提高后续使用加载的该Groovy脚本的准确性,Spring脚本加载器在将该Groovy脚本作为JavaBean加载至Spring上下文中之前,也即在图1所示的步骤S103之前,还要对该Groovy脚本进行语法检查,并确定对该Groovy脚本的语法检查通过。其中,可以通过Spring脚本加载器中的语法检查单元对该Groovy脚本进行语法检查,也即对该Groovy脚本进行编译,在编译通过后再将该Groovy脚本作为JavaBean加载至Spring上下文中,否则提示编译错误。In the embodiment of the present application, in order to improve the accuracy of the Groovy script loaded by subsequent use, before the Spring script loader loads the Groovy script as a JavaBean into the Spring context, that is, before step S103 shown in FIG. 1 , Also check the grammar of the Groovy script, and determine that the grammar check of the Groovy script passes. Among them, the syntax checking unit in the Spring script loader can check the syntax of the Groovy script, that is, compile the Groovy script, and then load the Groovy script into the Spring context as a JavaBean after the compilation is passed, otherwise it prompts to compile mistake.
并且,考虑到在实际应用中,普通的语法检查只检查该Groovy脚本的语法是否正确,例如Groovy自带的GroovyClassLoader。如果在该Groovy脚本中只定义了一个名字,例如为test,其语法并没有错误,因此普通的语法检查会认为对该只定义了一个名字的Groovy脚本进行的语法检查通过。但实际上该Groovy脚本除了定义的该名字之外并没有任何其他功能,也就是并没有起到一个JavaBean的功能,因此将该Groovy脚本作为一个JavaBean加载至Spring上下文中没有任何意义。Moreover, considering that in practical applications, ordinary syntax checking only checks whether the syntax of the Groovy script is correct, such as the GroovyClassLoader that comes with Groovy. If only one name is defined in the Groovy script, such as test, its grammar is not wrong, so the normal grammar check will consider that the grammar check of the Groovy script with only one name defined is passed. But in fact, the Groovy script does not have any other functions except the defined name, that is, it does not function as a JavaBean, so it does not make any sense to load the Groovy script as a JavaBean into the Spring context.
本申请实施例中为了避免上述Groovy脚本不规范,使得加载该Groovy脚本毫无疑义的问题,对该Groovy脚本进行语法检查的方法具体为,判断该Groovy脚本中是否包含至少一个继承于设定基类的子类,当判断结果为是时,确定对该Groovy脚本的语法检查通过,否则,确定对该Groovy脚本的语法检查不通过。In the embodiment of the present application, in order to avoid the problem that the above-mentioned Groovy script is not standardized, so that there is no doubt about loading the Groovy script, the method for checking the syntax of the Groovy script is specifically to determine whether the Groovy script contains at least one element inherited from the set base For the subclass of the class, when the judgment result is yes, it is determined that the grammar check of the Groovy script is passed; otherwise, it is determined that the grammar check of the Groovy script is not passed.
也就是说,本申请实施例中除了对Groovy脚本进行普通的语法检查之外,还要检查该Groovy脚本中是否包含至少一个继承于设定基类的子类,其中,该设定基类可以根据需要进行设定。例如,当该Groovy脚本用于对外部系统发送的报文格式进行格式转换时,该设定基类可以设定为具有格式转换功能的基类,但是该基类并不包括具体对哪个外部系统发送的报文、或者外部系统的哪个端口发送的报文、或者何种格式的报文进行该格式转换。该Groovy脚本中包含继承于上述设定基类的子类就是指,将该基类所具有的格式转换功能具体的应用于哪个外部系统发送的报文,或者外部系统的哪个端口发送的报文,或者何种格式的报文进行该格式转换的子类。That is to say, in the embodiment of the present application, in addition to performing ordinary syntax checking on the Groovy script, it is also necessary to check whether the Groovy script contains at least one subclass inherited from the set base class, wherein the set base class can be Set as required. For example, when the Groovy script is used to convert the format of the message sent by the external system, the setting base class can be set as the base class with the format conversion function, but the base class does not include which external system The format conversion is performed on the sent message, or which port of the external system sent the message, or the message in which format. The Groovy script includes a subclass inherited from the above-mentioned base class, which means that the format conversion function of the base class is specifically applied to the message sent by the external system, or the message sent by the port of the external system , or the subclass of the format of the message for which the format conversion is performed.
继续沿用上例,假设该Groovy脚本用于对外部系统A和外部系统B发送的报文格式进行格式转换,其中,外部系统A以格式a发送报文,外部系统B以格式b发送报文,而本地系统只能解析格式c的报文,则可以设定两个基类,第一个是将格式a转换为格式c的方法,第二个是将格式b转换为格式c的方法。该Groovy脚本中的一个子类继承于第一个基类,即为,将外部系统A以格式a发送的报文通过第一个基类的方法转换为格式c的报文,另一个子类继承于第二个基类,即为将外部系统B以格式b发送的报文通过第二个基类的方法转换为格式c的报文。从而,在采用本申请实施例的方法对该Groovy脚本进行语法检查时,确定该Groovy脚本中包含了至少一个继承于设定基类的子类,语法检查通过。而如果该Groovy脚本中只定义了一个名字,例如定义为test,则采用本申请实施例的方法进行语法检查时,虽然普通的语法并没有错误,但是Groovy脚本中未包含任何继承于设定基类的子类,因此语法检查不通过。Continuing with the above example, assume that the Groovy script is used to convert the formats of messages sent by external system A and external system B, where external system A sends messages in format a, and external system B sends messages in format b. If the local system can only parse messages of format c, two base classes can be set, the first is a method for converting format a to format c, and the second is a method for converting format b to format c. A subclass in the Groovy script inherits from the first base class, that is, the message sent by the external system A in format a is converted into a message in format c by the method of the first base class, and another subclass Inherited from the second base class, that is to convert the message sent by the external system B in format b into a message in format c through the method of the second base class. Therefore, when using the method of the embodiment of the present application to check the grammar of the Groovy script, it is determined that the Groovy script contains at least one subclass inherited from the set base class, and the grammar check passes. And if only one name is defined in the Groovy script, such as being defined as test, then when using the method of the embodiment of the present application to check the grammar, although the common grammar is not wrong, the Groovy script does not include any character inherited from the set base. class, so the syntax check fails.
通过本申请实施例提供的上述语法检查,当语法检查不通过时,则提示编译错误,当语法检查通过时,Spring脚本加载器将该Groovy脚本作为JavaBean加载至Spring上下文中。为了提高该Spring脚本加载器所在的系统的响应速度,本申请实施例中采用懒加载的方式加载该Groovy脚本,也即采用懒加载的方式将该Groovy脚本作为JavaBean加载至Spring上下文中。Through the above grammar check provided by the embodiment of the present application, when the grammar check fails, a compilation error is prompted, and when the grammar check passes, the Spring script loader loads the Groovy script as a JavaBean into the Spring context. In order to improve the response speed of the system where the Spring script loader is located, the Groovy script is loaded in a lazy loading manner in the embodiment of the present application, that is, the Groovy script is loaded into the Spring context as a JavaBean in a lazy loading manner.
图2为本申请实施例提供的Groovy脚本加载的详细过程,具体包括以下步骤:Fig. 2 is the detailed process of loading the Groovy script provided by the embodiment of the present application, which specifically includes the following steps:
S201:Spring脚本加载器将数据库中存储的Groovy脚本读取到缓存中。S201: The Spring script loader reads the Groovy script stored in the database into the cache.
S202:获取该Groovy脚本的属性信息,根据获取的属性信息生成对应的XML配置文件,并加载至Spring上下文中。S202: Obtain attribute information of the Groovy script, generate a corresponding XML configuration file according to the acquired attribute information, and load it into the Spring context.
S203:判断该Groovy脚本中的语法是否正确,若判断结果为是,则执行步骤S204,否则执行步骤S206。S203: Determine whether the grammar in the Groovy script is correct, if the determination result is yes, execute step S204, otherwise execute step S206.
S204:判断该Groovy脚本中是否包含至少一个继承于设定基类的子类,若判断结果是,则执行步骤S205,否则执行步骤S206。S204: Judging whether the Groovy script contains at least one subclass inherited from the set base class, if the judging result is yes, go to step S205, otherwise go to step S206.
S205:采用懒加载的方式将该Groovy脚本作为JavaBean加载至Spring上下文中。S205: Load the Groovy script as a JavaBean into the Spring context in a lazy loading manner.
S206:提示编译错误。S206: A compilation error is prompted.
其中,上述过程中的步骤S203和步骤S204的执行顺序不分先后。Wherein, the execution order of step S203 and step S204 in the above process is not in particular order.
图3为本申请实施例提供的Groovy脚本加载装置,具体包括:Fig. 3 is the Groovy script loading device that the embodiment of the present application provides, specifically includes:
Groovy脚本缓存管理单元301,用于读取数据库中存储的Groovy脚本;Groovy script cache management unit 301, used to read the Groovy script stored in the database;
SpringXML配置组装单元302,用于获取所述Groovy脚本的属性信息,根据获取的属性信息生成对应的XML配置文件,并加载至Spring上下文中;The SpringXML configuration assembly unit 302 is used to obtain the attribute information of the Groovy script, generate a corresponding XML configuration file according to the obtained attribute information, and load it into the Spring context;
BeanProcessor单元303,用于将所述Groovy脚本作为JavaBean加载至Spring上下文中,并将Spring上下文中加载的其他JavaBean提供给加载的所述Groovy脚本引用,或者将加载的所述Groovy脚本提供给Spring上下文中加载的其他JavaBean引用。The BeanProcessor unit 303 is used to load the Groovy script as a JavaBean into the Spring context, and provide other JavaBean loaded in the Spring context to the loaded Groovy script reference, or provide the loaded Groovy script to the Spring context Other JavaBean references loaded in .
所述Groovy脚本缓存管理单元301具体用于,将数据库中存储的所述Groovy脚本读取到缓存中。The Groovy script cache management unit 301 is specifically configured to read the Groovy script stored in the database into the cache.
所属装置还包括:The attached device also includes:
语法检查单元304,用于在所述BeanProcessor单元将所述Groovy脚本作为JavaBean加载至Spring上下文中之前,对所述Groovy脚本进行语法检查,并确定对所述Groovy脚本的语法检查通过。The grammar checking unit 304 is configured to check the grammar of the Groovy script before the BeanProcessor unit loads the Groovy script into the Spring context as a JavaBean, and determine that the grammar check of the Groovy script passes.
所述语法检查单元304具体用于,判断所述Groovy脚本中是否包含至少一个继承于设定基类的子类,当判断结果为是时,确定对所述Groovy脚本的语法检查通过,否则,确定对所述Groovy脚本的语法检查不通过。The syntax checking unit 304 is specifically used to determine whether the Groovy script includes at least one subclass inherited from the set base class, and when the judgment result is yes, determine that the syntax check of the Groovy script is passed; otherwise, It is determined that the syntax check of the Groovy script fails.
所述BeanProcessor单元303具体用于,采用懒加载的方式将所述Groovy脚本作为JavaBean加载至Spring上下文中。The BeanProcessor unit 303 is specifically configured to load the Groovy script as a JavaBean into the Spring context in a lazy loading manner.
具体的上述Groovy脚本加载装置可以位于Spring脚本加载器中。The specific above-mentioned Groovy script loading device may be located in the Spring script loader.
图4为本申请实施例提供的Spring脚本加载器具体实现结构示意图,如图4所示,Spring脚本加载器中的Groovy脚本缓存管理单元读取数据库中的Groovy脚本至缓存中,SpringXML配置组装单元获取Groovy脚本的属性信息,并生成对应的XML配置文件加载至Spring上下文中,语法检查单元检查该Groovy脚本的语法是否出错,并检查该Groovy脚本中是否包含至少一个继承于设定基类的子类,若检查通过,则BeanProcessor单元采用懒加载的方式将该Groovy脚本作为一个JavaBean加载至Spring上下文中。Fig. 4 is the specific implementation structural diagram of the Spring script loader that the embodiment of the present application provides, as shown in Fig. 4, the Groovy script cache management unit in the Spring script loader reads the Groovy script in the database to the cache, and the SpringXML configuration assembly unit Obtain the attribute information of the Groovy script, and generate the corresponding XML configuration file and load it into the Spring context. The syntax checking unit checks whether the syntax of the Groovy script is wrong, and checks whether the Groovy script contains at least one child that inherits from the set base class. Class, if the check is passed, the BeanProcessor unit loads the Groovy script as a JavaBean into the Spring context in a lazy loading manner.
本申请实施例提供一种Groovy脚本加载方法及装置,该方法Spring脚本加载器读取数据库中存储的Groovy脚本,获取该Groovy脚本的属性信息,生成对应的XML配置文件并加载至Spring上下文中,最后将该Groovy脚本作为JavaBean加载至Spring上下文中。由于在Spring框架下的多个JavaBean可以根据需要互相引用,因此本申请实施例中将Groovy脚本作为一个JavaBean加载至Spring上下文中,可以使该Groovy脚本在需要扩展功能时,直接引用Spring上下文中的其他JavaBean,其他JavaBean在需要扩展该Groovy脚本的功能时,也可以直接引用同样作为JavaBean的该Groovy脚本,从而提高了Groovy脚本的可扩展性和使用的灵活性。The embodiment of the present application provides a Groovy script loading method and device, in which the Spring script loader reads the Groovy script stored in the database, obtains the attribute information of the Groovy script, generates a corresponding XML configuration file and loads it into the Spring context, Finally, the Groovy script is loaded into the Spring context as a JavaBean. Since multiple JavaBeans under the Spring framework can refer to each other as needed, the Groovy script is loaded into the Spring context as a JavaBean in the embodiment of this application, so that the Groovy script can directly refer to the Other JavaBean, when other JavaBean needs to extend the function of the Groovy script, can also directly refer to the Groovy script which is also a JavaBean, thereby improving the scalability and flexibility of the Groovy script.
显然,本领域的技术人员可以对本申请进行各种改动和变型而不脱离本申请的精神和范围。这样,倘若本申请的这些修改和变型属于本申请权利要求及其等同技术的范围之内,则本申请也意图包含这些改动和变型在内。Obviously, those skilled in the art can make various changes and modifications to the application without departing from the spirit and scope of the application. In this way, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalent technologies, the present application is also intended to include these modifications and variations.
Claims (10)
Priority Applications (2)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201210135681.3A CN103383646B (en) | 2012-05-03 | 2012-05-03 | A kind of Groovy script loading method and device |
HK13114360.8A HK1187123B (en) | 2013-12-30 | Method and device for loading groovy script |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201210135681.3A CN103383646B (en) | 2012-05-03 | 2012-05-03 | A kind of Groovy script loading method and device |
Publications (2)
Publication Number | Publication Date |
---|---|
CN103383646A CN103383646A (en) | 2013-11-06 |
CN103383646B true CN103383646B (en) | 2016-05-04 |
Family
ID=49491446
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201210135681.3A Expired - Fee Related CN103383646B (en) | 2012-05-03 | 2012-05-03 | A kind of Groovy script loading method and device |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN103383646B (en) |
Families Citing this family (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN114546349B (en) * | 2020-11-25 | 2025-03-25 | 中盈优创资讯科技有限公司 | A mapping method based on Groovy script in the service activation process |
CN113360212A (en) * | 2021-06-30 | 2021-09-07 | 远光软件股份有限公司 | Application program starting method, computer device and computer readable storage medium |
Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101158901A (en) * | 2007-11-27 | 2008-04-09 | 北大方正集团有限公司 | A Method of Bridging Enterprise Level and Ordinary Level JAVABEAN |
US7747945B1 (en) * | 2004-09-22 | 2010-06-29 | International Business Machines Corporation | Data validation rules for acord documents |
CN101819530A (en) * | 2010-04-30 | 2010-09-01 | 山东中创软件工程股份有限公司 | Program object generation method and device and computer |
-
2012
- 2012-05-03 CN CN201210135681.3A patent/CN103383646B/en not_active Expired - Fee Related
Patent Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US7747945B1 (en) * | 2004-09-22 | 2010-06-29 | International Business Machines Corporation | Data validation rules for acord documents |
CN101158901A (en) * | 2007-11-27 | 2008-04-09 | 北大方正集团有限公司 | A Method of Bridging Enterprise Level and Ordinary Level JAVABEAN |
CN101819530A (en) * | 2010-04-30 | 2010-09-01 | 山东中创软件工程股份有限公司 | Program object generation method and device and computer |
Also Published As
Publication number | Publication date |
---|---|
CN103383646A (en) | 2013-11-06 |
HK1187123A1 (en) | 2014-03-28 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US20190235883A1 (en) | Dynamically Loaded Plugin Architecture | |
US20080235661A1 (en) | System and method for using annotations to automatically generate a framework for a custom javaserver faces (jsf) component | |
US8984502B2 (en) | Systems and methods for composing or decomposing a composite image for firmware update images | |
US11093222B2 (en) | Generating interfaces from annotated entity definitions for developing applications | |
US8762977B2 (en) | Mobile device software management method and apparatus | |
RU2571592C2 (en) | Method and system for managing static data structures of legacy software in dynamic class loader environments | |
US8924944B2 (en) | Implementation of distributed methods that support generic functions | |
US20120246653A1 (en) | Generic command parser | |
CN106559438A (en) | A kind of program method for uploading and device based on objective network platform | |
CN111290806A (en) | Calling method and device of application program interface, computer equipment and storage medium | |
US11093220B2 (en) | Generating interfaces from data and service definitions for developing applications | |
US20090144711A1 (en) | System and method for common compiler services based on an open services gateway initiative architecture | |
CN113384896B (en) | Resource packaging method, device, equipment and medium based on Unity | |
US8914482B2 (en) | Translation of technology-agnostic management commands into multiple management protocols | |
US8584080B2 (en) | Modeling and generating computer software product line variants | |
US8135757B2 (en) | Generating references to reusable code in a schema | |
CN116414774A (en) | File migration method, device, equipment and storage medium | |
CN103383646B (en) | A kind of Groovy script loading method and device | |
US11194602B2 (en) | Runtime execution of entities and services in an application object runtime environment | |
US20140304701A1 (en) | Object-Oriented Open Framework for Campaign Generation | |
US11803786B2 (en) | Enterprise integration platform | |
US20130067058A1 (en) | Providing external access to service versions via a bundle framework | |
US10606569B2 (en) | Declarative configuration elements | |
CN104021000A (en) | Method for configuring spring data source through property file in dynamic path | |
WO2018093642A1 (en) | System integration using configurable dataflow |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
REG | Reference to a national code |
Ref country code: HK Ref legal event code: DE Ref document number: 1187123 Country of ref document: HK |
|
C14 | Grant of patent or utility model | ||
GR01 | Patent grant | ||
REG | Reference to a national code |
Ref country code: HK Ref legal event code: GR Ref document number: 1187123 Country of ref document: HK |
|
TR01 | Transfer of patent right | ||
TR01 | Transfer of patent right |
Effective date of registration: 20191210 Address after: P.O. Box 31119, grand exhibition hall, hibiscus street, 802 West Bay Road, Grand Cayman, Cayman Islands Patentee after: Innovative advanced technology Co.,Ltd. Address before: Cayman Islands Grand Cayman capital building, a four storey No. 847 mailbox Patentee before: ALIBABA GROUP HOLDING Ltd. |
|
CF01 | Termination of patent right due to non-payment of annual fee | ||
CF01 | Termination of patent right due to non-payment of annual fee |
Granted publication date: 20160504 |