Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Hot deployment of springcloud

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

When springcloud is deployed as a runnable jar package, hot deployment is not supported if the business script groovy is directly typed into the jar.

The business script groovy needs to be placed in another git directory to be written, and the linked target is used to be placed in the project during development, and the deployment is not entered into the jar.

nhmicro Framework Code Address: github.com/jeffreyning/nh-micro

download groovy script from git repository at startup and load it into springcloud application with micro-git-sync module function in nhmicro framework

At the same time, it can also support dynamic publishing, that is, after submitting a new groovy to the git repository, it will be automatically downloaded and hot deployed to the springcloud application.

the advantage of using that micro-git-sync module are:

1. When the application runs according to the executable jar package, it also supports script hot deployment.

2, quasi-real-time automatic loading of new script code in remote git.

3, you can load scripts according to the specified version.

Configure MicroGitSync Set git remote address and local download directory

If init-method="initRep" is set, the remote git repository is checked for code updates in quasi-real time, and if so, it is automatically downloaded.

Version can be set to the specified version, set to head to indicate the latest version

cloneFlag indicates whether it is completely clone at startup

openFlag indicates whether it is valid. It can be set to false in the development environment to avoid downloading remotely when debugging programs.

Settings Load groovy from local download directory

Note Set depends-on to ensure git loads at boot after download is complete

Micro-mvc can be integrated not only with springmvc but also with springcloud

The controller layer of Springcloud is changed to interface annotation. Springcloud and springboot related annotations are still used to implement configuration such as service registration route, but @InjectGroovy annotation needs to be added to the controller interface to set the association groovy implemented by the interface.

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);}

Spring configuration uses GroovyBeanScannerConfigurer scan controller interface

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; }}

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report