When Springcloud is deployed in a runnable jar package, hot deployment is not supported if the business script groovy is scored directly into the jar.
Business script groovy needs to be written in another Git directory, developed with the linked target placed in project, and deployed without breaking into the jar.
Nhmicro Framework code Address: Https://github.com/jeffreyning/nh-micro
Download groovy scripts from the Git repository at startup with the Micro-git-sync module feature in the NHMICRO framework loaded into the Springcloud app,
It can also support dynamic publishing, where new groovy is submitted to the GIT repository and automatically downloaded and thermally deployed to the Springcloud app.
The advantages of using the Micro-git-sync module are:
1, enabling the application to run in accordance with the executable jar package, also supports scripting hot deployment.
2, quasi-real-time automatic loading of new script code in remote git.
3, the script can be loaded according to the specified version.
Configure Microgitsync to set git remote address and local download directory
If init-method= "Initrep" is set, the remote Git repository will be checked for code updates and then downloaded automatically.
Version can be set to the latest version, set to head
Cloneflag Indicates whether the clone is complete at startup
Openflag Indicates whether it is valid and can be set to false in the development environment to avoid downloading from the remote when debugging the program.
<bean id="gitSync" class="com.nh.micro.sync.git.MicroGitSync" init-method="initRep" lazy-init="false"> <property name="localPath" value="h:/temp/git"></property> <property name="remotePath" value="https://github.com/nhmicro/test-sync-groovy.git"></property> <property name="cloneFlag" value="true"></property> <property name="openFlag" value="${openFlag}"></property> <property name="version" value="head"></property></bean>
Set to load groovy from the local download directory
Note The settings depends-on make sure that the git download completes after the boot load
<bean id= "Groovyinitutil" class= "Com.nh.micro.rule.engine.core.GroovyInitUtil" init-method= "Initgroovy" lazy -init= "false" depends-on= "Gitsync" > <property name= "fileList" > <list> < ; Bean class= "Com.nh.micro.rule.engine.core.GFileBean" > <property name= "Rulestamp" value= "true" ;</property> <property name= "Jarfileflag" value= "true" ></property> <property name= "Dirflag" value= "true" ></property> <property name= "Rulepath" value= "/gro ovy/"></property> </bean> <bean class=" Com.nh.micro.rule.engine.core.GFile Bean "> <property name=" Rulestamp "value=" true "></property> <proper Ty name= "Jarfileflag" value= "false" ></property> <property name= "Dirflag" value= "true" >&L T;/property> <property name= "Rulepath" value= "h:/temp/git/test-sync/groovy/" ></property> </bea n> </list> </property> </bean>
MICRO-MVC can not only integrate with SPRINGMVC but also with Springcloud
Springcloud the controller layer to interface annotations still implement the service registration routing configuration using Springcloud and springboot related annotations, But the Controller interface needs to add @injectgroovy annotations to set the interface implementation of the associated groovy.
package com.nh.micro.springcloud.demo.web;import org.apache.log4j.Logger;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.cloud.client.ServiceInstance;import org.springframework.cloud.client.discovery.DiscoveryClient;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.bind.annotation.RequestParam;import org.springframework.web.bind.annotation.ResponseBody;import org.springframework.web.bind.annotation.RestController;import com.nh.micro.service.InjectGroovy;@InjectGroovy(name="ComputeGroovy")@RestControllerpublic interface ComputeController { @RequestMapping(value = "/add" ,method = RequestMethod.GET) @ResponseBody public Integer add(@RequestParam(value="a") Integer a, @RequestParam(value="b") Integer b);}
Use Groovybeanscannerconfigurer Scan Controller interface in spring configuration
<bean class="com.nh.micro.service.GroovyBeanScannerConfigurer"> <property name="scanPath" value="com.nh.micro.springcloud.demo.web"></property> </bean>
Computecontroller Interface Implementation Computegroovy.groovy
package groovyimport javax.annotation.Resource;import org.springframework.cloud.client.ServiceInstance;import org.springframework.cloud.client.discovery.DiscoveryClient;import org.springframework.web.bind.annotation.RequestParam;import org.apache.log4j.Logger;class ComputeGroovy {private final Logger logger = Logger.getLogger(getClass());//@Resource(name="discoveryClient")//public DiscoveryClient client; public Integer add(@RequestParam Integer a, @RequestParam Integer b) { //GroovyExecUtil.execGroovyRetObj("TestGroovy", "test"); Integer r = a + b; System.out.println(r); //ServiceInstance instance = client.getLocalServiceInstance(); //logger.info("/add, host:" + instance.getHost() + ", service_id:" + instance.getServiceId() + ", result:" + r); return r; }}
Springcloud Hot Deployment