springcloud熱部署

springcloud按照可運(yùn)行jar包部署時(shí),如果直接將業(yè)務(wù)腳本groovy打入jar則不支持熱部署。

阿壩州ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場(chǎng)景,ssl證書(shū)未來(lái)市場(chǎng)廣闊!成為創(chuàng)新互聯(lián)建站的ssl證書(shū)銷售渠道,可以享受市場(chǎng)價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:13518219792(備注:SSL證書(shū)合作)期待與您的合作!

需要將業(yè)務(wù)腳本groovy放置到另一個(gè)git目錄下編寫(xiě),開(kāi)發(fā)時(shí)使用linked目標(biāo)放置到project中,部署是不打入jar中。

nhmicro框架代碼地址:https://github.com/jeffreyning/nh-micro

借助nhmicro框架中micro-git-sync模塊功能在啟動(dòng)時(shí)從git倉(cāng)庫(kù)中下載groovy腳本加載到springcloud應(yīng)用中,
同時(shí)還可以支持動(dòng)態(tài)發(fā)布,即提交新groovy到git倉(cāng)庫(kù)后,會(huì)自動(dòng)下載并熱部署到springcloud應(yīng)用中。

使用micro-git-sync模塊優(yōu)點(diǎn)是:

1, 使應(yīng)用按照可執(zhí)行jar包運(yùn)行時(shí),也支持腳本熱部署。

2, 準(zhǔn)實(shí)時(shí)自動(dòng)加載遠(yuǎn)程git中的新腳本代碼。

3, 可以按照指定版本加載腳本。

配置MicroGitSync設(shè)置git遠(yuǎn)程地址和本地下載目錄

如果設(shè)置了init-method="initRep",則準(zhǔn)實(shí)時(shí)檢查遠(yuǎn)程git倉(cāng)庫(kù)是否有代碼更新,有則自動(dòng)下載。

Version可以設(shè)置指定的版本,設(shè)置為head表示最新版本

cloneFlag表示啟動(dòng)時(shí)是否完全clone

openFlag表示是否有效,開(kāi)發(fā)環(huán)境中可以設(shè)置為false,避免調(diào)試程序時(shí)從遠(yuǎn)程下載。

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

設(shè)置從本地下載目錄中加載groovy

注意設(shè)置depends-on確保git下載完成后在啟動(dòng)加載

    <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="/groovy/"></property>
                </bean>
                <bean class="com.nh.micro.rule.engine.core.GFileBean">
                    <property name="ruleStamp" value="true"></property>
                    <property name="jarFileFlag" value="false"></property>
                    <property name="dirFlag" value="true"></property>
                    <property name="rulePath" value="H:/temp/git/test-sync/groovy/"></property>
                </bean>                 
            </list>
        </property>
    </bean>

Micro-mvc不但可以與springmvc整合還可以與springcloud整合

Springcloud的controller層改為接口注解仍使用springcloud和springboot相關(guān)注解實(shí)現(xiàn)服務(wù)注冊(cè)路由等配置,但controller接口上需要添加@InjectGroovy注解設(shè)置接口實(shí)現(xiàn)的關(guān)聯(lián)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")
@RestController
public interface ComputeController {

    @RequestMapping(value = "/add" ,method = RequestMethod.GET)
    @ResponseBody
    public Integer add(@RequestParam(value="a") Integer a, @RequestParam(value="b") Integer b);

}

Spring配置中使用GroovyBeanScannerConfigurer掃描controller接口

    <bean class="com.nh.micro.service.GroovyBeanScannerConfigurer">
        <property name="scanPath" value="com.nh.micro.springcloud.demo.web"></property>
    </bean>

ComputeController接口實(shí)現(xiàn)ComputeGroovy.groovy

package groovy

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

當(dāng)前標(biāo)題:springcloud熱部署
鏈接地址:http://muchs.cn/article22/gecccc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供服務(wù)器托管、網(wǎng)站收錄、網(wǎng)站營(yíng)銷網(wǎng)站建設(shè)、定制開(kāi)發(fā)、定制網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)